+1 vote
by (130 points)

I have downloaded the Trial version of Rebex SecureMail.

I have created a c# console program to test on MailMessage. I have tried loading a .msg file from local drive and trying to save the attachments inside. It contains a .msg file attachment but it was detected as a "message/rfc822" content type and the attachment is save as ".eml" format instead of ".msg" format.

Is there any way to detect the correct attachment format (.msg) and save it as ".msg" format instead.

1 Answer

0 votes
by (70.2k points)

This is feature of the MailMessage class.
It detects embedded messages and provides them as MailMessage objects. The Content-type is unified to message/rfc822.
However, you can save the embedded message in both ".eml" or ".msg" formats.

It can be done like this:

for (int i = 0; i < mail.Attachments.Count; i++)
    var att = mail.Attachments[i];
    var message = att.ContentMessage;
    if (message != null)
        message.Save(string.Format("ATT{0}.msg", i), MailFormat.OutlookMsg);
        message.Save(string.Format("ATT{0}.eml", i), MailFormat.Mime);

This will not persist the original content of the embedded message.

If you want to save the unmodified attachment data, you have to use the MsgMessage class. It is available for free on our labs page.

Note: We are currently finalizing the MsgMessage class to be included into our portfolio as a standard product. If you want to try the current beta version, please download it from here.