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.