We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

When converting MSG with images attachments to PDF those images are added to the PDF page

Hello,

When converting a MSG to PDF the output PDF contains the images attachments in the PDF pages.
I used the code provided by you in the example: https://docs.aspose.com/email/net/saving-an-email-as-pdf/.
In Aspose.Email older versions this problem do not happen. Can you take a look please?

string dataDir = RunExamples.GetDataDir_KnowledgeBase();
MailMessage mailMsg = MailMessage.Load(dataDir + “message3.msg”);
MemoryStream ms = new MemoryStream();
mailMsg.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml); // <- the problem seems to be here

// create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new Aspose.Words.Loading.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
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save(dataDir + “SaveEmailAsPDF_out.pdf”, saveOptions);

This issue can be reproduced in your online converter with the file I uploaded.
https://products.aspose.app/email/conversion/msg-to-pdf

MSG file with images attachements.zip (1.2 MB)

Thanks

@duvidasAspose

Please use MhtSaveOptions.SaveAttachments property as shown below to avoid exporting attachment in output MHTML.

MailMessage mailMsg = MailMessage.Load(MyDir + "MSG file with images attachements.msg");
MhtSaveOptions saveOptions = new MhtSaveOptions();
saveOptions.SaveAttachments = false;
mailMsg.Save(MyDir + "output.mhtml", saveOptions);

Thanks for your reply.

The code you provided works.
Just a clarification, can that property “SaveAttachments” set to false have any implications in embedded resources ou inline attachments? or just affects the regular attachments?

@duvidasAspose

The MhtSaveOptions.SaveAttachments property is used either to export attachment in output MHTML or not. Could you please share some more detail about your concerns?

The concern was if by “export attachment in output MHTML” it includes only regular attachments or also can include inline attachments and embedded imagens.

@duvidasAspose

The inline images do not ignore by using MhtSaveOptions.SaveAttachments property with false value.

Please use MhtSaveOptions.SkipInlineImages property to avoid rendering inline images to MHTML.

Thanks, I appreciate the clarification.