Code to convert msg to PDF like that:
private static byte[] SavingAnEmailAsPdf(Aspose.Email.MailMessage mailMessage)
{
try
{
Logging.LogMessageInfo(“Start save mail to pdf”);
MemoryStream ms = new MemoryStream();
mailMessage.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
// create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = 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);
MemoryStream msPdf = new MemoryStream();
// create an instance of HtmlSaveOptions and set the SaveFormat to Html
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save(msPdf, saveOptions);
Logging.LogMessageInfo("Save mail to pdf successfully");
return msPdf.ToArray();
}
catch (Exception ex)
{
Logging.LogMessageInfo("Save mail to pdf failed: " + ex.ToString());
return null;
}
}
Test 1:
Aspose.mail(Version 20.10.0.0) + Aspose.word (Version 20.11.0.0)
Test 2:
Aspose.mail(Version 20.9.1.0) + Aspose.word (version 17.9.0.0)
Output PDF does NOT contain image of attachment. -> This is okay.
Watch output pdf here: EmailOutputByOldAsposeVersion.pdf (569.8 KB)
Looks like there is a bug in combination Aspose.mail(Version 20.10.0.0) + Aspose.word (Version 20.11.0.0).
Can you please check if you get the same problem?
After observing the two PDF files and Image, it seems to be an issue that needs investigation. First of all, can you please try using Aspose.Email for .NET 20.12 and Apsose.Words for .NET 20.12 on your end. Secondly, please save MHTML to file rather stream when exporting using Aspose.Email. If the MHTML is fine and PDF has got issue then it is Aspose.Words related issue. Otherwise, if there is issue in MHTML then it is Aspose.Email related issue.
Can you please share the source MSG/EML file that we may verify on our and log the ticket.
You can open the MHTML ouput in Browser or in MS Word. You can compare the visible output of MHTML with that of viewed in Source file. MHTML is intermediate format for rendering EML/MSG to PDF. So, if the problem is in MHTML file then its Aspose.Email issue. Otherwise, if MHTML is rendered fine but PDF has issue then it Aspose.Words issue. I hope it will make sense now.