Home » C# Programming

How to parse .msg file without using Outlook object model in .NET?

How to parse .msg file without using Outlook object model in .NET?

I want to extract From, To, Subject and Body from tjhe .msg file.

Any pointer will be helpful.



4 Answers Found


Answer 1


Read the following article which describes how to read an Outlook msg file in C# without the Outlook object model.

Reading an Outlook MSG File in C#

Also take a look at the following links.

Parse Outlook .msg files without using Outlook

Parse .msg file using C#


Answer 2


See if below steps works for you.


See if you can  Convert MSG file to txt file (http://us.generation-nt.com/best-way-convert-msg-file-txt-help-22848812.html). Convert txt file into XML format. Use XmlTextReader to read the file content Convert the XML file into your own format using XSLT transformation

Code which can be used for XSLT transformation:

Code I am using for XSLT Transformation:

XslCompiledTransform xslt;

String xsltFileName =”mainTrans.xslt”;

XPAthDocument xDoc ; // reading using XPathNavigation

XsltSettings settings = new XsltSettings(true, false);

XmlUrlResolver resourceResolver = new XmlUrlResolver();

resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(), “Prefixdllname”);

XPathDocument xslDoc = new XPathDocument(Assembly.GetExecutingAssembly().GetManifestResourceStream(prefix + "." + xsltFileName));

xslt.Load(xslDoc, settings, resourceResolver); // Loading Embedded XSLT resources into  XslCompiledTransform

// Main document part processing

xslt.Transform(xDoc, args, intermidaryOutput); // Debugging at this point


You can use XmlReader instead of XPathDocument.


For code sample on codeplex refer link. http://www.codeproject.com/KB/office/MsgReader.aspx

Not sure whether you are allowed to use third party/free source code.

Also Check whether below thread will give you result.


Nasir Khan

Answer 3

Go through below link: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/fdb9117d-f507-431b-8f29-8d5d823de665

Answer 4

I've had a lot of success using MSG .NET to parse 1000s of .msg files.

It is commercial library http://www.independentsoft.de/msg/index.html





<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure