We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MapiMessage with attached email - how to get the attachment data?

I'm creating a Network.Outlook.MapiMessage object by drag and drop from Outlook and then extracting the data from the message and writing it to my database. To get the attachments I have been iterating the Attachments collection and reading from the Attachment.BinaryData property.

This works fine for most attachments, but when I dropped an email that had another email attached my code failed because the BinaryData property was nothing. I can see for this attachment that the data is held in the Attachment.ObjectData property, so I tried to read the details from Attachment.ObjectData.Data but it didn’t work. If I write this byte array out to a msg file and then try to open it I get an invalid file message.

I noticed that the Attachment object has a Save method that can be used to write the attachment to a file, but this doesn’t work either when the attachment is an email message.

Can you please tell me how to access this type of attachment? Specifically I need to know where I get the byte array that I can save to disk and then open the file.


Thank you for inquiry.

To get the nested email attachment, please check MapiAttachment.ObjectData.IsOutlookMessage. You may try the below example to save a nested message attachment to disk as MSG format.

MapiMessage msg = …; // This is the main message
foreach (MapiAttachment attachment in msg.Attachments)
if (attachment.ObjectData != null &&
// For nested email attachments - save as msg
MapiMessage msgMessage = MapiMessage.FromStream((new MemoryStream(attachment.ObjectData.Data)));
msgMessage.Save(attachment.FileName + “.msg”);
// For other attachments