c# read outlook .msg file code example

Example: c# download outlook msg file attachment

Microsoft.Office.Interop.Outlook.Application oOutlookApp = new Microsoft.Office.Interop.Outlook.Application(); 
MailItem oMailItem = null;

oMailItem = oOutlookApp.CreateItemFromTemplate("e:\\test.msg");
Attachments oAttachments = oMailItem.Attachments;
for (int i = 1; i <= oAttachments.Count; i++)
{
    Attachment oAttachment = oAttachments[i];
    oAttachment.SaveAsFile(AppDomain.CurrentDomain.BaseDirectory + oAttachment.FileName);
    Marshal.ReleaseComObject(oAttachment);
    oAttachment = null;
}
Marshal.ReleaseComObject(oAttachments);
oAttachments = null;
Marshal.ReleaseComObject(oMailItem);
oMailItem = null;
oOutlookApp.Quit();
Marshal.ReleaseComObject(oOutlookApp);
oOutlookApp = null;