Convert EMAIL to PDF (.msg to pdf file)

Hi Team , I am generating pdf file from .msg file.
I have used your logic your are provided in the webpage ( C# API to Export EMAIL to PDF | products.aspose.com)

MailMessage message = MailMessage.Load("sourceFile.msg");
// save EMAIL as a HTML 
message.Save("HtmlOutput.html", SaveOptions.DefaultHtml);
// load HTML with an instance of Document
Document document = new Document("HtmlOutput.html");
// call save method while passing SaveFormat.Pdf
document.Save("output.pdf", SaveFormat.Pdf); 

The above logic is working fine for generating pdf file only for email body. But From address, to address, subject, cc, bcc, send and attachments are not showing in the pdf. Can anyone provide the code changes to display that stuff as well in the pdf file.

Thanks,
Ramakrishna.

Hello @krishaluri ,

Welcome to our support forum.
To display the message fields when saving to HTML, use the HtmlFormatOptions.

var htmlSaveOptions = SaveOptions.DefaultHtml;
htmlSaveOptions.HtmlFormatOptions = HtmlFormatOptions.WriteHeader; //save the message headers to output HTML using the formatting options
// save EMAIL as a HTML 
message.Save("HtmlOutput.html", htmlSaveOptions);