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 MailMessage
2. Save the email message to MemoryStream as MHTML
3. Load the stream using Aspose.Words
4. Save the message as PDF


Sample Code for Converting an Email Message to PDF


[C#]

Code:
MailMessagemailMsg = MailMessage.Load("About Aspose-1.msg");

MemoryStreamms = new MemoryStream();

//Save as MHTML
mailMsg.Save(ms, MailMessageSaveType.MHtmlFromat);

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

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

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

//save the document to Html file
document.Save("About Aspose.pdf", saveOptions);

[VB.NET]

Code:
Dim mailMsg As MailMessage = MailMessage.Load("About Aspose-1.msg")

Dim ms As New MemoryStream()

'Save as MHTML
mailMsg.Save(ms, MailMessageSaveType.MHtmlFromat)

'create an instance of LoadOptions and set the LoadFormat to Mhtml
Dim loadOptions = New Aspose.Words.LoadOptions()
loadOptions.LoadFormat = LoadFormat.Mhtml

'create an instance of Document and load the MTHML from MemoryStream
Dim document = New Aspose.Words.Document(ms, loadOptions)

'create an instance of HtmlSaveOptions and set the SaveFormat to Html
Dim saveOptions = New Aspose.Words.Saving.PdfSaveOptions()

'save the document to Html file
document.Save("About Aspose.pdf", saveOptions);