How to convert MSG to PDF with To: From: Subject: header information

How do I convert MSG to PDF with To: From: Subject: header information?


I want the same result as if I saved msg to PDF in outlook.

thank you.

Example code, that uses Aspose.Email and Aspose.Words (combination is needed).

First convert the MSG-file to a MHTML-stream, load this stream into Aspose.Words.Document and save this document as a PDF-file.
class Program
{
static void Main(string[] args)
{
using (var memStream = new System.IO.MemoryStream())
{
using (var mailMessage = Aspose.Email.Mail.MailMessage.Load(@“C:\Temp\MyEmail.msg”))
{
mailMessage.Save(memStream, Aspose.Email.Mail.MailMessageSaveType.MHtmlFormat);
}
memStream.Position = 0;

        <span style="color:blue;">var</span> loadOptions = <span style="color:blue;">new</span> Aspose.Words.<span style="color:#2b91af;">LoadOptions</span>() { LoadFormat = Aspose.Words.<span style="color:#2b91af;">LoadFormat</span>.Mhtml };
        <span style="color:blue;">var</span> doc = <span style="color:blue;">new</span> Aspose.Words.<span style="color:#2b91af;">Document</span>(memStream, loadOptions);

        <span style="color:blue;">var</span> saveOptions = <span style="color:blue;">new</span> Aspose.Words.Saving.<span style="color:#2b91af;">PdfSaveOptions</span>();
        doc.Save(<span style="color:#a31515;">@"C:\Temp\MyEmail.pdf"</span>, saveOptions);
    }
}

}

Hi Hans,


Thank you for writing to Aspose support team.

You can use the MhtmlFormatter for further formatting of the message that further allows you to decide which fields to write to output and which fields to hide. You may also visit the Conversion to Mhtml section of our documentation for further information in this regard. Please feel free to contact us if you need further assistance.