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

  • Question

  • 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.

     

    Wednesday, April 28, 2010 6:52 AM

Answers

  •  

    See if below steps works for you.

     

    1. See if you can  Convert MSG file to txt file (http://us.generation-nt.com/best-way-convert-msg-file-txt-help-22848812.html).
    2. Convert txt file into XML format. Use XmlTextReader to read the file content
    3. 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.

    http://blogs.msdn.com/pcreehan/archive/2007/02/06/howto-get-email-messages-from-exchange-to-sharepoint.aspx


    Nasir Khan
    • Proposed as answer by Nasir Khan - CTS Wednesday, April 28, 2010 8:21 AM
    • Marked as answer by Vinod Bhoite Wednesday, April 28, 2010 8:29 AM
    • Unmarked as answer by Vinod Bhoite Thursday, April 29, 2010 10:01 AM
    • Unproposed as answer by Vinod Bhoite Thursday, April 29, 2010 10:01 AM
    • Marked as answer by Vinod Bhoite Friday, April 30, 2010 5:18 AM
    Wednesday, April 28, 2010 8:13 AM

All replies

  • Hi,

    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#

    Wednesday, April 28, 2010 8:04 AM
  •  

    See if below steps works for you.

     

    1. See if you can  Convert MSG file to txt file (http://us.generation-nt.com/best-way-convert-msg-file-txt-help-22848812.html).
    2. Convert txt file into XML format. Use XmlTextReader to read the file content
    3. 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.

    http://blogs.msdn.com/pcreehan/archive/2007/02/06/howto-get-email-messages-from-exchange-to-sharepoint.aspx


    Nasir Khan
    • Proposed as answer by Nasir Khan - CTS Wednesday, April 28, 2010 8:21 AM
    • Marked as answer by Vinod Bhoite Wednesday, April 28, 2010 8:29 AM
    • Unmarked as answer by Vinod Bhoite Thursday, April 29, 2010 10:01 AM
    • Unproposed as answer by Vinod Bhoite Thursday, April 29, 2010 10:01 AM
    • Marked as answer by Vinod Bhoite Friday, April 30, 2010 5:18 AM
    Wednesday, April 28, 2010 8:13 AM
  • Go through below link: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/fdb9117d-f507-431b-8f29-8d5d823de665
    Nasir Khan
    Wednesday, April 28, 2010 8:20 AM
  • 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

    ----

    Frank

    Friday, January 28, 2011 6:44 AM