How to load and save .MSG messages with as little modifications as possible?

0 votes
asked Jun 8, 2015 by Rebex KB (8,190 points)

I am writing a utility that removes attachments from Outlook .MSG messages using MailMessage class and it looks like some information is getting lost during the process. How do I solve this?

Applies to: Rebex Secure Mail

1 Answer

+1 vote
answered Jun 8, 2015 by Lukas Pokorny (103,050 points)

Loading a .MSG message into the MailMessage object involves a conversion from Outlook .MSG format to the standard MIME format (saving is a reverse process) and properties that don't have MIME equivalents are lost (such as Exchange-only addresses). Additionally, MSG's proprietary HTML-embedded-in-RTF message bodies are converted to separate HTML and RTF views, which enhances compatibility but further modifies the original message.

This makes MailMessage object unsuitable for scenarios that involve both loading and saving of the same MSG file. As o solution to this limitation, we have published Rebex Secure Mail with Outlook Message support package at Rebex Labs that adds a MSG-based OutlookMessage object. Unlike MailMessage, it retains the original message structure:

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

// load an Outlook .MSG mail message
message.Load("outlook-mail.msg");

// work with the message
// ...

// save the message
message.Save("outlook-mail.msg"); 
...