Free Support Forum -

How to extract embedded messages from a MSG file


We get mails from our agents which further contain embedded mails. Other type of attachments are also there. How to differentiate the attached MSG files /other file types and save them to disc?


Hi Cornelius,

This is a very common case where the attachments of an email can further be MSG files and can be determined using the IsOutlookMessage property of attachment’s ObjectData as following. Let us know if you have any addtional query related to Aspose.Email.

int i = 0;

var message = Aspose.Email.Outlook.MapiMessage.FromFile(“task.msg”);

var attachments = message.Attachments;

foreach (var attachment in attachments)


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


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

if(embeddedMessage.MessageClass.Equals(“IPM.Appointment”, StringComparison.InvariantCultureIgnoreCase))


MapiCalendar calendar = (MapiCalendar)embeddedMessage.ToMapiMessageItem();

calendar.Save(“C:\temp\out.ics”, AppointmentSaveFormat.Ics);