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

Free Support Forum - aspose.com

MSG-file in Attachments

Hi! I have a question. If I have Email with the attached MSG how can I get this MSG and work with it like a MailMessage?

Hi Albert,

Thank you for contacting Aspose.Email support team.

If you are loading the source message using MailMessage class, you can use the following code sample for this purpose:

Sample Code:

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:teal;mso-no-proof:yes”>MailMessage<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> msg = MailMessage.Load(“Test
with attachment message.msg”
, MessageFormat.Msg);<o:p></o:p>

Attachment att = msg.Attachments[0];

if (att.ContentType.MediaType == "message/rfc822")


MemoryStream ms = new MemoryStream();


MailMessage attMsg = MailMessage.Load(ms);

Console.WriteLine("From: " + attMsg.From);

Console.WriteLine("To: " + attMsg.To);

Console.WriteLine("Subject: " + attMsg.Subject);


In case you are using MapiMessage class for loading such a source message file, you can refer to the following code sample for your kind reference to achieve this:

Sample Code:

MapiMessage message = Aspose.Email.Outlook.MapiMessage.FromFile("Test with attachment message.msg");

MapiAttachmentCollection attachments = message.Attachments;

foreach (MapiAttachment attachment in attachments)


if (attachment.ObjectData != null && attachment.ObjectData.IsOutlookMessage)


MapiMessage embeddedMessage = Aspose.Email.Outlook.MapiMessage.FromStream(new System.IO.MemoryStream(attachment.ObjectData.Data));

//Now use MailMessageInterpretor for conversion of MapiMessage to MailMessage

MailMessageInterpretor mi = MailMessageInterpretorFactory


MailMessage mailMsg = mi.Interpret(embeddedMessage);

Console.WriteLine("From: " + mailMsg.From);

Console.WriteLine("To: " + mailMsg.To);

Console.WriteLine("Subject: " + mailMsg.Subject);



Please feel free to write us back in case you have any other query/inquiry related to Aspose.Email. We'll try to assist you further as soon as possible.

Thanks! It’s great!

Hi Albert,

Thank you for the feedback and please feel free to write to us in case you have any additional query/inquiry related to Aspose.Email. We’ll be glad to assist you further.