Outlook MSG parser and writer for .NET

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

This is a preview version of Rebex MSG library for direct manipulation of Outlook .MSG mail messages. Rebex Secure Mail component contains a 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 MsgMessage class allows you to work with Outlook .MSG messages without losing any data.

Download Rebex MSG for .NET »

Change log

2020-08-05 - API update. Renamed OutlookMessage to MsgMessage, etc.
2017-04-18 - Added support for setting properties using PropertyLid.
2015-07-10 - Added Properties collection to OutlookMessage and OutlookAttachment classes.
2015-05-28 - First version released.

Getting started

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 MsgMessage class
var message = new MsgMessage();	

// load an Outlook .msg mail message

// work with message
// ...

// save the message somewhere

Working with attachments

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

// 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);

Working with subject, body and addresses

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

// 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 MsgMessage class
var message = new MsgMessage();

// load a message

// 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);
		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);
message.Properties.SetValue(PropertyLid.InternetAccountName, KnownPropertySet.Common, name);

// save the message

Send us feedback

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