How to open .eml files using Outlook MAPI in C#?

CubaLibre picture CubaLibre · May 17, 2011 · Viewed 13.7k times · Source

I have a C# application that reads .msg files and extracts the body and the attachments. But when I try to load a .eml file the application crashes. I am loading the files like this:

MailItem mailItem = (MailItem)outlookApp.CreateItemFromTemplate(msgFileName);
mailItem.SaveAs(fullFilename, OlSaveAsType.olHTML); // save body in html format
for(int i = 0; i < mailItem.Attachments.Count; i++)
    mailItem.Attachments[i].SaveAsFile(filename); // save attachments

This works fine with .msg files, but it doesn't work for .eml files. I don't understand why .eml files don't work, because I can open .eml files in Outlook 2010.

How can I load .eml files using the Outlook Primary Interop Assembly?

Answer

lsalamon picture lsalamon · May 20, 2011