Attached msg files not loading correctly

In Aspose.Email 3.5, an email attachment does not load correctly. In the AttachmentCollection the Name is missing the attachment. Please see the attached file as an example.


Aspose.Email.License lic = new Aspose.Email.License();
lic.SetLicense(@“Aspose.Total.lic”);
Aspose.Email.Mail.MailMessage mailMessage = Aspose.Email.Mail.MailMessage.Load(@“Test Attachment.msg”);

Regards,
James

Hi James,


Thanks for writing to Aspose.Email support team.

I have tested the sample message and found that Attachment name is present there as shown in the attached snapshot. I have used the following code for testing the scenario:

Aspose.Email.Mail.MailMessage mailMessage = Aspose.Email.Mail.MailMessage.Load(@“Test Attachment.msg”);
if (mailMessage.Attachments.Count > 0)
{
Attachment attch = mailMessage.Attachments[0];
Console.WriteLine("Attachment Name = " + attch.Name);
if (attch.ContentType.MediaType == “message/rfc822”)
{
attch.Save(attch.Name + “.eml”);
}
}

If we analyze this message in OutlookSpy, it can be observed that no attachment file name with extension is found in the properties list. We can use the attachment content type to get the MediaType of the attachment and if it is "message/rfc822", then its a mail type attachment. Also the "Name" property is only the display name of the attachment name and cannot be used always as attachment file name.

Please feel free to write us back if you have any other query in this regard.

Thanks for the reply. Is it possible to save the attachment as a .msg rather than eml?

Hi James,

Yes, the attachment email can be saved to MSG format as well. Once the condition for attachment type checking is verified, you can save the attachment to MemoryStream and load it in MailMessage instance, after which it can be saved to MSG as shown in the following code sample:

Sample Code:

MailMessage msg = MailMessage.Load(samplemessage, MessageFormat.Eml);
Attachment att = msg.Attachments[0];
if (att.ContentType.MediaType == "message/rfc822")
{
    MemoryStream ms = new MemoryStream();
    att.Save(ms);
    MailMessage attMsg = MailMessage.Load(ms);

    attMsg.Save("AttachmentMsg.msg", MailMessageSaveType.OutlookMessageFormatUnicode);
}