Aspose license creating error ("No html part found!") while importing

Hi Team,
We are using ASPOSE pdf and ASPOSE email licenses, only few messages are throwing error while importing, getting error like “No html part found”. The same email after forwarding to another account and importing again from different account or else importing from sent item of my account, this error is not occuring.
So ONLY I am getting from the original email.
If I removed any one of the license either ASPOSE PDF or ASPOSE EMAIL, the email import is working fine but with watermark it is creating the PDF file.

Watermark: Evaluation Only. Created with Aspose.Email for .NET. Copyright 2002-2022 Aspose Pty Ltd.
image.jpg (115.6 KB)

@ShanPwc,

This question should be asked in the Aspose Email API forum. I will be moving the post there so you get answered your question.

Thank you for preferring Aspose Products.

1 Like

Hello, @ShanPwc!
Can you, please, provide us with the original sample message in the eml format? And the code sample that you use for convertation.
Note that a message doesn’t always contain html part. With no license applied html part is added to a message to display the watermark.
Thank you.

Please find the attached sample email which is creating “No html part found!” error but the error was occurring only with the original message, if it is a downloaded msg file or forwarded email, this error is not occurring so you are not able to reproduce from your end.

SampleEmail.zip (1.1 MB)

The below code we are using to convert to PDF.
Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
Aspose.Email.License licenseEmail = new Aspose.Email.License(); //Pass the license file embedded in the assembly
licensePdf.SetLicense(“Aspose.PDF.NET.lic”);
licenseEmail.SetLicense(“Aspose.Email.NET.lic”); // Convert the message to pdf format
Aspose.Email.MailMessage mailMsg = Aspose.Email.MailMessage.Load(new MemoryStream(msg)); MemoryStream ms = new MemoryStream();
mailMsg.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml); //Instantiate the License class
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(ms, new Aspose.Pdf.MhtLoadOptions()); pdfDoc.PageInfo.IsLandscape = true; var filePath = path + fileId.ToString() + “.pdf”;
pdfDoc.Save(filePath);
_logger.LogInformation($“Outlook Mail import: {extensionType} Conversion Completed”);

@ShanPwc
Thanks for your sample and code. We are processing your request and will answer assap.

@ShanPwc,

We’ve investigated mht file created by your code but haven’t found any problems on our end.

If you open mht with the text editor, you can see html part there.

So, the problem appears with loading the document in Aspose.Pdf.

As a workaround, we suggest saving the document in html rather than mht.


Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();

Aspose.Email.License licenseEmail = new Aspose.Email.License(); //Pass the license file embedded in the assembly

licensePdf.SetLicense("Aspose.PDF.NET.lic");

licenseEmail.SetLicense("Aspose.Email.NET.lic"); // Convert the message to pdf format

Aspose.Email.MailMessage mailMsg = Aspose.Email.MailMessage.Load(new MemoryStream(msg));

using (MemoryStream ms = new MemoryStream())

{

    mailMsg.Save(ms, new HtmlSaveOptions{HtmlFormatOptions = HtmlFormatOptions.WriteHeader});

    ms.Position = 0;

    Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(ms, new Aspose.Pdf.HtmlLoadOptions());

    pdfDoc.PageInfo.IsLandscape = true;

    var filePath = path + fileId.ToString() + “.pdf”;

    pdfDoc.Save(filePath);

}

The issue has been identified and resolved, some of the emails having the content on the body tag, in that case we are getting this error. we are seeing this error minimum one or two email out of every 50 emails.
Is speccally while importing bulk email this is a big problem.
I think you guys need to give proper guidance for your customers.

So the code has been changed like below.
try
{
filePath = this.GetPdfFileSavedPath(msg,SaveOptions.DefaultMhtml,new Aspose.Pdf.MhtLoadOptions());}
catch (Exception ex)
{
filePath = this.GetPdfFileSavedPathForHtml(copyEmailResult.BodyContent);
}

Thank you for your help!

We’re always ready to help!