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.
Hi James,
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”);
}
}
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);
}