0 votes
by (8.4k 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?

1 Answer

+1 vote
by (144k 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 released Outlook MSG file format library for .NET 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

// work with the message
// ...

// save the message