How can I parse the winmail.dat file using TNEF Parsing? - c#

I have inbound mail system using postmark(C# luanguage). Some of the email which was received from outlook service provider contains winmail.dat attachment and facing alignment issue. How to get actual email content attachment from this winmail.dat attachment?
I am tried TNEF parsing using MIME kit. Receiving exception like cannot convert attachment to tnef attachment.

Related

C# MailKit - How to create a Rtf message

I'm trying to send a message in rtf format but on reception it is not interpreted correctly by gmail, etc. (except Mail.app on MacOS). Here is a sample code. Some client application consider it as "text".
String body = #"{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red255\green0\blue0;} This line is the default color\line \cf2 This line is red\line \cf1 This line is the default color}"
message.Body = new TextPart("rtf") { Text = body };
Where am I wrong?
As jdweng points out, most mail clients do not support RTF.
Google mail only supports HTML and plain-text messages as far as I know.
I tried testing this by using Outlook to send an RTF message to GMail, but alas, my Exchange server always overrides the RTF by converting it to HTML and so GMail always receives text/html instead of text/rtf.
I might be able to get Outlook to send text/rtf if I configure it to send via some non-Exchange account, but I'm too lazy to bother.

Can the S/MIME Content Type of e-mail be explicitly defined?

The recipient expects a signed and encrypted message with attachment.
In their specification, under the e-mail attachment section they state "The Content-Type of the MIME-Parts has to be Application/octet-stream".
Our attachment is of the required content-type. The signed only message contains different content-types but they do not seem to cause any trouble since when sending a signed only message the recipient is able to parse our message and sends an ack.
When encrypting the message the resulting Content-Type is Content-Type: application/pkcs7-mime;.
After contacting the recipient, they were able to provide us with the error message of their automated system which reads: Unknown Email-ContentType: application/pkcs7-mime
Their error message leaves me to believe that other than the attachment-type the e-mail content-type needs to be of octet stream as well.
I'm using C# with Rebex is it possible to force a specific content type?
Forcing specific content types is possible using Rebex API (at least in this case), but you have to use the low-level MIME API. So if you are currently using the MailMessage class, you might use this approach:
using Rebex.Mail;
using Rebex.Mime;
using Rebex.Mime.Headers;
...
var message = new MailMessage();
...
message.Sign(...);
message.Encrypt(...);
MimeMessage mime = message.ToMimeMessage();
mime.ContentType = new ContentType(MediaTypeNames.Application.Octet);
mime.Save("message.eml");
However, be aware that this will result in a message that appears to only contain binary data, and it will most likely not be recognized as an S/MIME message by common mail software and libraries, including Rebex Secure Mail.

Is it Possible to Reply From an .EML file?

I would like to know if it is possible to open and reply as a response message on top of a saved .eml file using C#?
If yes, are there any guides that I can follow?
I am able to do so with EWS EmailMessage where the message resides in Inbox. However, due to requirements, I am required to retrieve and reply from a saved .eml file instead of replying from the email in Inbox directly.
Thank you.
No you can't do this using the EWS reply operations because EWS is a Server side API while using the EWS Managed API you using Client side library that just instrumenting the SOAP call to the backend whenever an action is taken. You can temporary import the EML back in the server https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-import-items-by-using-ews-in-exchange and then you reply and then delete the Message again if don't want it to exist. If your want to send using EWS you didn't want to import the message use something like mimekit to generate the MIME of the response message offline http://www.mimekit.net/docs/html/Frequently-Asked-Questions.htm then you can just sent the Mime generated by mimekit via EWS.
In theory you could achieve this, by first opening the EML file (please see this question and answer):
Retrieve Email Information from .EML Files
And then when you have the contents of the message in code, copy the data over to whatever email-sending API you are using.
Step 1:-
Click the message options menu in the top right corner of the message. Select Save email.
Step 2:-
Save the file. The file name will default to the subject line of the email, with special characters removed. Your download options depend on whether you're using Front on the web or in the desktop app:
*Web: Your file automatically saves to wherever you have it set up in your browser settings (like your Downloads folder)
*Desktop app: You will get the “Save As” prompt where you can rename the file and choose your download location
Step 3:-
You will see your .eml file in your chosen location. You can attach it to a message via drag-and-drop or with the attachment file picker.

Is it possible to send an attachment in Outlook as a URL

I have an Outlook addin that handles attachments by sending them to our server and then embedding a link into the body of the email containing the URL to the uploaded attachment.
This works but it is not 100% satisfactory because the URLs can get broken depending in the email client and the sender will not see their attachments listed at the top of there email where they are use to seeing them.
Ideally what I would like to do is exactly what is being done for OneDrive.
Currently if I add an attachment and provide a URL as the source it will download the file and send it as a normal attachment which is the exact opposite of what I want. I have noticed that if it fails to download the file it will then just send the URL as an attachment which is what I want. But sending broken URLs is not very useful.
Using
Outlook.MailItem.Attachments.Add("https://myserver.com/somefile", 7, 1, "MyAttachment")
If I set the attachment type to '7' which is what is used for OneDrive attachments I can get it to send the URL but it will first complain about not being able to set some access rights and if the sender clicks OK to continue anyway the attachment will appear to the sender and the receiver as residing on OneDrive which it is not, but clicking the URL will download the file from my server as I want.
My question is: Is it possible to send a none OneDrive URL as an attachment?
(I expect the answer is no, but I am hoping some Outlook guru out there may know some trick to do this.)
My other alternative it to wrap my URLs in an small html file that is then sent as a normal attachment and when opened will provide the link to the actual file.

attachments with ics file in c#

I am trying to send an ICS (calendar) file to someone that read it using Office365, using C#.
Sending just the ICS works fine. But I have to attach a file.
At this point, the mail is received without calendar, or the calendar is attached to the email and cannot be used, or the attachment is missing.
I tried 2 different ways:
1. send attachment inside VEVENT, using ATTACH;ENCODING=BASE64;VALUE=BINARY;X-FILENAME=file.txt:, but this does not show any attachment in Office365 (like here: Attaching a file to an iCalendar)
2. send attachment as a separate file, and attach it to VEVENT using ATTACH:CID:, but this time the calendar file is displayed as attachment
The second way should work if I can format the mail message to look like this:
multipart/mixed
multipart/alternative
text/plain
text/calendar;method=REQUEST
text/calendar (with a content-disposition:attachment)
(as described in Multipart email with text and calendar: Outlook doesn't recognize ics)
If I send a calendar invite using Outlook365, the message looks like that.(but instead of the calendar as attachment, the image or doc is attached)
but using System.Net.Mail.MailMessage, I can generate a message like this
multipart/mixed
multipart/alternative
text/plain
text/calendar;method=REQUEST
multipart/mixed
text/plain (with a content-disposition:attachment)
Desktop version of Outlook 2007 shows both calendar and attachment, so it seems that Outlook365 is very strict about the format.
But how can I send, using .NET classes, an email that does not have the extra multipart/mixed section? MailMessage class generate for the Attachments collection a new section with content type multipart/mixed, insead of adding them to the top level.

Categories