Aspose Email considering attached Images of .jpg or .png type as embedded images in .msg file

Hi Team,
we are using Aspose email and Aspose word to convert a .msg file to a PDF file.
The requirement is to convert the Body of the .msg file(including the embedded images in the email body) to a PDF.
However the attached Images(not embedded in the body) of known types like (.JPG, .PNG) are also getting converted and is placed at the end of the PDF document.

I have attached the sample email, PDF out put and the sample code for the same. Kindly advise at the earliest. ThSample Input Out put and Code.zip (198.9 KB)
ank you so much.

Hello @RAJASHM,

Unfortunately, we can not affect the order of its rendering in mht, as the attached image isn’t embedded.

Hi @margarita.samodurova, Thank you and sorry.I am not seeking advise on the rendering order of the images rather I want to restrict the image to attached to the PDF.
The requirement details as below.

  1. If the image is attached to .MSG file as an attachment then it should not be there in the converted PDF
  2. But if the image is embedded within the body of the .msg file then it should be present in the converted pdf.

Current behavior:
If any image of known type like (.JPG,.PNG) is attached to .msg file then the image is by default comming in converted PDF file. If the Image of type(.EMZ or .TIFF ) are attached to .msg file then those are not comming in converted PDF.

Please advise on how to restrict the known image types attached to .MSG file to get converted to pdf. But if the image is embedded to the body of the .msg file it should get converted to PDF without any restriction.

Hi @RAJASHM,

You need to set the MhtFormatOptions parameters in MhtSaveOptions.

The following parameters are used by default:

MhtFormatOptions.WriteHeader Or MhtFormatOptions.WriteOutlineAttachments

We recommend removing the MhtFormatOptions.WriteOutlineAttachments parameter:

Dim saveOptions As MhtSaveOptions = New MhtSaveOptions()
saveOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader
eml.Save("Sample Image.mht", saveOptions)

I hope it works, please, share your feedback on the results.

Hi @margarita.samodurova, Thank you.
It does not attach the image to the PDF.
However it also does not convert the embedded images into PDF as well.
Please advise if there any other way where we can get the embedded images converted and at the same time we will not include the image attached to .msg file.

Thank you

Hi @RAJASHM,

You can be sure the code works, as it does on our side. Please, check the attached msg with an embedded image using the following code:

Dim eml = MailMessage.Load("A Day in the Park.msg")
Dim saveOptions = New MhtSaveOptions()
saveOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader
eml.Save("A Day in the Park.mht", saveOptions) 

All the embedded images are present in mht.

Please, try and share your feedback.
A Day in the Park.zip (467.0 KB)

Hi @margarita.samodurova, Thank you so much. It worked really well for Converting from .MSG to .MHT file.
Our business requirement is to convert .mht to .pdf by using aspose.Mail and Aspose.word

when we are converting the .mht file created through the code to .docx it is not converting the embedded images. It is comming as X sign.

Please find the attached ZIP containing the attached .mht file and .Docx file and the sample code.
sample code .mht to .docx and input output files.zip (10.9 KB)

Please advise.

Hi @RAJASHM,

Glad to hear it worked converting from msg to mht. However, converting to .docx is outside the scope of Aspose.Email. We will redirect your issue to our colleagues from Aspose.Words.

@RAJASHM Unfortunately I cannot reproduce the issue on my side. Could you please make sure the Apose.Words have the access to load image from the web? Also you could use the LoadOptions.ResourceLoadingCallback property to control the loading process.