Error saving msg to PDF with external content

I get a “System.Net.WebException” error when calling the following code to save an MSG file to PDF. This is a marketing email with lots of external links. I assume the server is no longer available. I have the code in a try catch block but the error is not trapped. I run this in a thread. The thread just terminates and does not report an error to the try catch block.


EXCEPTION THROW:
System.Net.WebException occurred
Message: A first chance exception of type ‘System.Net.WebException’ occurred in System.dll
Additional information: Unable to connect to the remote server

CODE EXECUTED (line with *** is the line where the error occurs)
Dim message = Aspose.Email.Mail.MailMessage.Load(msgName)
Dim mhtSaveOptions As MhtSaveOptions = New MhtSaveOptions()
mhtSaveOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader

Using msgStream = New MemoryStream()
message.Save(msgStream, mhtSaveOptions)
msgStream.Position = 0
Dim document = New Aspose.Words.Document(msgStream)

document.Save(PDFOutputName)
document = Nothing
End Using
mhtSaveOptions = Nothing
message.Dispose()

this line throws the error:

Dim document = New Aspose.Words.Document(msgStream)

Hi Simon,

Thank you for writing to Aspose Support team.

We have investigated the issue from Aspose.Email’s perspective and the MHTML file is generated fine in no time without any exception. For further investigation, we converted your MSG file to MHT format using MS Outlook. When this file is tried to be opened with MS Word, it takes alot of time to open and doesn’t come back. Aspose.Words seems to resemble the same behavior and it doesn’t seem to be an issue with the API.


For further opinion, we are moving this thread to Aspose.Total forum so that our Aspose.Words team can share their feedback about this problem.

Is there a way to get the file to PDF without using Aspose.Words?

Hi Simon,

The ZIP file attached to your first post looks corrupted and cannot be opened. Can you please attach the sample MSG file again for further investigation?

Best Regards,

Your coworkers were able to work with the file. Could the long load time be due to the file corruption?

These emails open just fine in outlook. MS Word and Aspose have issues with them. I think it is a timeout with the rendering of dead links. Since we can open these emails in outlook and even forward them, they are not corrupt.


Regardless of the state of the email (corrupt or not) the error that is thrown should be trapped. It appears to be when trying to load the external links. Your Aspose.Mail department told me that it was a timeout issue. This error should not cause a catastrophic failure of your library.

Can you trap the error inside Aspose.Words DLL and allow it to continue with loading?

Much Thanks

Upon further investigation, I was able to save the attached MSG file by first opening the MSG file in outlook then doing a FILE\SAVE_AS and saving the file to MHT. That MHT file opens in a browser and renders successfully.


I thought this information might help.

Hi Simon,

Thanks for the details. My colleague Waqas had deleted your sample after testing so we do not have any copy of that message. Can you please share the file again for further investigation?

Best Regards,

Hi Simon,

I was not able to reproduce the issue using the latest version of Aspose.Words (i.e. 15.8.0). I get attached PDF at my end using your code with latest versions of Aspose.Email and Aspose.Words.

Can you please test with the latest versions and let us know if you still see and issue?

Best Regards,

The latest build I see on your downloads page is 15.7 in the bundle.

Hi Simon,

Latest version of Aspose.Words was excluded from Aspose.Total installer because of an issue. It will be fixed soon. You can download 15.8.0 from http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx

Best Regards,

I am getting the same error behavior. I have the sample code you tested inside a .NET SYSTEM.THREADING.TASKS.TASK thread. Is this code thread safe?

Hi Simon,

Yes, it is. Can you please share a simple console application to reproduce the issue?

Best Regards,

The attached console application hangs up on this line:

Dim document = New Aspose.Words.Document(msgStream)

using the attached msg file

The same code hangs both inside thread and if you just run the function outside of a thread.

Hi Simon,

Sorry, I was still unable to reproduce the issue using the latest versions of Aspose.Words and Aspose.Email. I was able to successfully run your sample many times. The only issue I see is that it takes some time in downloading external resources but there is no exception and PDF is generated successfully.

From error description it looks like there is some network issue at your end while downloading external resources. Can you please confirm if your network was working fine when you tested it?

Best Regards,