Convert EML to MHTML to PDF & Write Complete From / To Email Addresses in Header | C# .NET

Hi,

Context:
I want to convert an EML to a PDF.

I followed Exporting EML to PDF - #2 by awais.hafeez, which advises to:

  1. convert from EML to MHTML with Aspose.Email

  2. convert from MHTML to PDF with Aspose.Words

The code is the following:

MemoryStream ms = new MemoryStream();

emlMessage.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);

// Convert MHTML as word doc

Aspose.Words.Loading.LoadOptions lo = new Aspose.Words.Loading.LoadOptions();

lo.LoadFormat = Aspose.Words.LoadFormat.Mhtml;

Aspose.Words.Document document = new Aspose.Words.Document(ms, lo);

// Convert Word Doc as PDF

Aspose.Words.Saving.PdfSaveOptions saveOptions = new Aspose.Words.Saving.PdfSaveOptions();

document.Save(fileStream, saveOptions);

Problem: I want to customize the formatting of the email information. For instance, I want the From field not to be formatted as such:

From: Quentin PERGELINE

But rather:

From: Quentin PERGELINE<quentin.pergeline@iwecloud.com>

As an example:
the EML: source.eml
the converted PDF: dest.pdf

Question: How can I customize the formatting of email info (especially the From field) during the conversion from an EML to a PDF?

Thanks
example.zip (273.6 KB)

@qpergeline,

To display complete email addresses in MHTML and PDF files, you need to enable appropriate options of MhtFormatOptions Enumeration:

Aspose.Email.MailMessage mailMsg = Aspose.Email.MailMessage.Load("C:\\Temp\\234866\\source.eml");
Aspose.Email.MhtSaveOptions mhtSaveOptions = Aspose.Email.MhtSaveOptions.DefaultMhtml;
mhtSaveOptions.MhtFormatOptions = Aspose.Email.MhtFormatOptions.WriteHeader | Aspose.Email.MhtFormatOptions.WriteCompleteEmailAddress;
mailMsg.Save("C:\\Temp\\234866\\eml to.mhtml", mhtSaveOptions);

Aspose.Words.Document doc = new Aspose.Words.Document("C:\\Temp\\234866\\eml to.mhtml");
doc.Save("C:\\Temp\\234866\\mhtml to.pdf");