Convert Microsoft Outlook MSG Email Message to PDF File

This technical tip explains how to convert an email message to PDF using Aspose.Email. Aspose.Email for .NET deals with network protocols and Microsoft Outlook features, and cannot handle direct conversion to PDF. To overcome this, the samples in this article use Aspose.Email to convert the email message to MHTML stream and then use Aspose.Words for .NET to load the MHTML stream and then save it as PDF. The following code shows converting email message to PDF using Aspose.Email in combination with Aspose.Words for .NET. This involves the following steps:

1. Load the email message using MailMessage2. Save the email message to MemoryStream as MHTML3. Load the stream using Aspose.Words4. Save the message as PDF

Sample Code for Converting an Email Message to PDF

[C#]

MailMessage mailMsg = MailMessage.Load("About Aspose-1.msg");

MemoryStream ms = new MemoryStream();

//Save as MHTMLmailMsg.Save(ms, MailMessageSaveType.MHtmlFromat);

//create an instance of LoadOptions and set the LoadFormat to Mhtmlvar loadOptions = new Aspose.Words.LoadOptions();loadOptions.LoadFormat = LoadFormat.Mhtml;

//create an instance of Document and load the MTHML from MemoryStreamvar document = new Aspose.Words.Document(ms, loadOptions);

//create an instance of HtmlSaveOptions and set the SaveFormat to Htmlvar saveOptions = new Aspose.Words.Saving.PdfSaveOptions();