Outlook MSG parser and writer for .NET

Read and write Microsoft Outlook MSG format using this .NET library

This is a trial version of the forthcoming version of Rebex Secure Mail which adds support for direct working with Outlook .msg mail messages. Rebex Secure Mail component already contains the MailMessage class which is able to load an Outlook .msg message, however it performs some internal conversions to be MIME compatible and therefore some internal .msg data are discarded. The OutlookMessage class allows you to work with Outlook .msg messages without losing any data.

Download Rebex Secure Mail with OutlookMessage class (trial) »

Have an active Rebex Secure Mail support contract?

This library is based on a trial beta version of Rebex Secure Mail. If you have already purchased Rebex Secure Mail, you can get an unlimited beta. Just contact us at support@rebex.net and we will send you a link.

Change log

2015-07-10 - Added Properties collection to OutlookMessage and OutlookAttachment classes.
2015-05-28 - First version released.

Getting started

First, get your trial key from http://www.rebex.net/support/trial-key.aspx and add it to your project's code.

The following C# code will show some typical scenarios.

Using and references

using Rebex.Mail;

Loading and saving Outlook .msg mail message

// create an instance of the OutlookMessage class
var message = new OutlookMessage();	

// load an Outlook .msg mail message
message.Load(@"C:\input\Outlook-mail.msg");	

// work with message
// ...

// save the message somewhere
message.Save(@"C:\output\Outlook-mail.msg");

Working with attachments

// create an instance of the OutlookMessage class
var message = new OutlookMessage();

// add an attachment
message.Attachments.Add(@"C:\data\file.txt", "file");

// list all attachments
foreach (var att in message.Attachments)
{
	Console.Write("{0} ({1}): ", att.DisplayName, att.FileName);
	if (att.Data != null)
		Console.WriteLine("{0}B", att.Data.Length);
	else
		Console.WriteLine();
}

Working with subject, body and addresses

// create an instance of the OutlookMessage class
var message = new OutlookMessage();

// set Subject field
message.Subject = "Hello world";

// set Body field
message.SetBody("Hello world!", null);	

// set From field
message.From.SetValues("John Doe", "john.doe@example.com");

// set To fields
message.To.Add("Robin", "robin@example.com");
message.To.Add("Bill", "bill@example.com");

Working with MAPI properties

// create an instance of the OutlookMessage class
var message = new OutlookMessage();

// load a message
message.Load(@"C:\input\Outlook-mail.msg");

// list all properties of the message
foreach (var prop in message.Properties)
{
	string id;
	switch (prop.Kind)
	{
		case PropertyKind.Tagged: id = prop.Tag.ToString(); break;
		case PropertyKind.NumericalNamed: id = prop.Lid.ToString(); break;
		case PropertyKind.StringNamed: id = prop.Name; break;
		default: id = "Invalid ID"; break;
	}

	if (prop.DataType == PropertyDataType.Binary)
		Console.WriteLine("{0} ({1}): length={2}", id, prop.DataType, ((byte[])prop.Value).Length);
	else
		Console.WriteLine("{0} ({1}): {2}", id, prop.DataType, prop.Value);
}

// set (add if not exists) some properties to the message
string name = string.Format("{0}@{1}", Environment.UserName, Environment.MachineName);
message.Properties.SetValue(PropertyTag.LastModifierName, name);
message.Properties.SetValue(PropertyTag.LastModificationTime, DateTime.UtcNow);

// save the message
message.Save(@"C:\output\Outlook-mail.msg");

Send us feedback

Do you have any comments or suggestions? Contact us at support@rebex.net.