Convert Outlook .msg file to MIME format in .NET

Files containing the .msg file extension are most commonly created by or saved from within one of the Microsoft Outlook email applications.

The MSG file contains information about a saved email file including the date of the message, the subject, who sent it, who received it and the contents of the email associated with the file. If attachments ares included with an email, that information will also be saved within the associated MSG file.

MsgConverter , than can be used to convert .msg files to MIME, is written in pure .NET, it does not require registration or any other components or libraries (including Outlook).

The following code snippet reads .msg file in .NET and saves it using MIME format to disk. MIME is shorthand for Multipurpose Internet Mail Extensions and is an Internet standard used to store and transport email messages.

// C#

using (MsgConverter converter = new MsgConverter(@"c:\outlook1.msg"))
{
    if (converter.Type == MsgType.Note)
    {
        IMail email = converter.CreateMessage();

        // Render message using MIME format to byte array
        byte[] mime = email.Render();

        // Save message to file using MIME message format
        email.Save(@"c:\mime.eml");
    }
}
' VB.NET

Using converter As New MsgConverter("c:\outlook1.msg")
If converter.Type = MsgType.Note Then
    Dim email As IMail = converter.CreateMessage()

	' Render message using MIME format to byte array
	Dim mime As Byte() = email.Render()

	' Save message to file using MIME message format
	email.Save("c:\mime.eml")
    End If
End Using

Tags: , , , ,

2 Responses to “Convert Outlook .msg file to MIME format in .NET”

  1. Andriy Homchenov Says:

    Is this the same process for convert .eml and .msg files into pdf files?

  2. Limilabs support Says:

    @Andriy,

    Mail.dll provides easy access to MIME email messages and a way for converting Outlook’s msg format to MIME message.

    When you have IMail object instance, you can easy access all email properties (such as Subject, Text, Attachments,…) and use external tool (such as PDFsharp) to a create pdf file.

Questions?

Consider using our Q&A forum for asking any questions.