Error converting EML to PDF due to allegedly corrupt file header

When converting some emails, the converter fails with “Cannot convert. The file is corrupt or damaged. Incorrect file header”.
However, when opening this email in Outlook, it loads just fine including attachments. No error here.
My company policy does not allow the specific file to be shared, but here is some more information:

Version: 25.9.0

EmailLoadOptions and conversion code:

EmailLoadOptions options = new()
        {
            DisplayHeader = true,
            DisplayFromEmailAddress = true,
            DisplayToEmailAddress = true,
            DisplayEmailAddresses = true,
            DisplayCcEmailAddress = true,
            DisplayBccEmailAddress = true,
            Depth = 2,
            TimeZoneOffset = TimeSpan.FromHours(2),
        };

using Converter converterGroupDocs = new(() => mailStream, _ => options);

converterGroupDocs.Convert(
    ctx => new PdfConvertOptions(),
    conversionCompletedCallback,
     CancellationToken.None
);

This is the exception, that has been thrown:

GroupDocs.Conversion.Exceptions.CorruptOrDamagedFileException: Cannot convert. The file is corrupt or damaged. Incorrect file header
 ---> Aspose.Pdf.InvalidPdfFileFormatException: Incorrect file header
   at #=zbYFkEb0m8XLicMDR5i57wF8GZRh4ezKkPQ==.#=zjpYUs5pOYNQo()
   at #=zbYFkEb0m8XLicMDR5i57wF8GZRh4ezKkPQ==..ctor(Stream #=z1BTxTk8=, String #=zlcid8O8=, Boolean #=zo1Skt$2TqBPi, ICustomSecurityHandler #=znWLgMkjqjmiX, CertificateEncryptionOptions #=ztJk4YO3M2L70)
   at #=zbYFkEb0m8XLicMDR5i57wF8GZRh4ezKkPQ==..ctor(Stream #=z1BTxTk8=)
   at #=z9X3Ts8yerjjCCSvbE_48MWRgPT9hTh4g2YTg7Ew=.#=zvvWixxU=(Stream #=z1BTxTk8=)
   at #=z$5tYAjyLZUtIA2BoOdCKfFxtkfIWd37uug==..ctor(Stream #=z1BTxTk8=)
   at #=z9X3Ts8yerjjCCSvbE_48MWRgPT9hTh4g2YTg7Ew=.#=zcT1UhX7Ajq7_(Stream #=z1BTxTk8=)
   at #=zrIAvGV7Wc2ijO$fGJIKr9LppELHl.#=zbI9veDs=(Stream #=z1BTxTk8=)
   at #=zrIAvGV7Wc2ijO$fGJIKr9LppELHl..ctor(Stream #=z1BTxTk8=)
   at Aspose.Pdf.Document.#=zm0QRBZU=(Stream #=zeIS55N0=, String #=zlcid8O8=, ICustomSecurityHandler #=znWLgMkjqjmiX, CertificateEncryptionOptions #=ztJk4YO3M2L70)
   at Aspose.Pdf.Document..ctor(Stream input, String password)
   at InvokeStub_Document..ctor(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zYcYgbjMB2YzksyWkWgrMYjTo3oS8(Object #=zPFJ6wXs=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zFMu3pjgfexOOP0JBmLtQDRTjvii5(Object #=zPFJ6wXs=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zgzvIc6ZdsiTU86GnAlG1RfXIsItTmQKn8UV8wKg=(#=qHQ7h9ksMgRZuXe5L3lVdA$jh3mf3GTphO8DG0_DQInM= #=zPFJ6wXs=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zet7byd3ALlbUFCeU55oPJ04HtGefTDM8zw==(dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd #=zPFJ6wXs=, #=qHQ7h9ksMgRZuXe5L3lVdA$jh3mf3GTphO8DG0_DQInM= #=zaoKv9xA=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zIOaiwawLX5bT92b6lP7bovioGT8q()
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY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zPFJ6wXs=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zakfvUX3dCWMc7uzmnYltUmwoXitG()
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=z6knwFPouYtxHGUXsPQKmpVHlr$2tQdSoYnKz0Xg=(Object #=zPFJ6wXs=, UInt32 #=zaoKv9xA=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zG4ZDZugn8SCHzwA3W4aPjmZKUA8E(Boolean #=zPFJ6wXs=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zG4ZDZugn8SCHzwA3W4aPjmZKUA8E(Boolean #=zPFJ6wXs=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=z9dgL3A12mAiFKH3V3s8pPpSlvuylcisswwLuOdO5nIrd()
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=zjdnJvmU5vuy5Z8G3ml5giTznyMkhnzBysxQLkz9gNkkU(Object[] #=zPFJ6wXs=, Type[] #=zaoKv9xA=, Type[] #=zqxU$XeA=, Object[] #=zc3YBpYA=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=za0a_4_qZezm_ZR5wlJXuhU8qRr8vDd5bY7NMH2k=(Stream #=zPFJ6wXs=, String #=zaoKv9xA=, Object[] #=zqxU$XeA=, Type[] #=zc3YBpYA=, Type[] #=zklfAgz4=, Object[] #=zlOh4JeA=)
   at dje_qRGUY4XJKKWEK7QXDSF6BD2CVXUCU29RY7QUC7G4RSMTN5SKDU3VA_ejd.#=z9YqOMZ0uTV2RIXkHBZrHwKM=(Stream #=zPFJ6wXs=, String #=zaoKv9xA=, Object[] #=zqxU$XeA=)
   at Aspose.Pdf.DocumentFactory.CreateDocument(Stream input, String password)
   at .(Stream , String )
   at .()
   at .()
   --- End of inner exception stack trace ---
   at ..(Exception )
   at System.AggregateException.Handle(Func`2 predicate)
   at .(CancellationToken )
   at GroupDocs.Conversion.Converter.(CancellationToken )
   at GroupDocs.Conversion.Converter.Convert(Func`2 convertOptionsProvider, Action`1 documentCompleted, CancellationToken cancellationToken)```

Version is 25.9.0

Hello @JuneTech ,

We’re sorry to hear that you’ve encountered this kind of issue when converting .eml files to .pdf. Unfortunately, without your sample file, it’s difficult to determine the exact cause of the problem — especially since you mentioned that it doesn’t happen with all files.

If you’re concerned about sharing sensitive information, you may remove or redact it from the file before sending it. To ensure privacy, we’ve also made this forum thread private, so only our support team will be able to access your file.

Additionally, you may try converting this file without using any custom EmailLoadOptions, as one of those options might be causing the issue.

We’ll be waiting for your sample document so that we can investigate this issue and assist you as soon as possible.

Hello,
unfortunately, those emails are from our customers and we must not share them in any way or form.

In version 23.12 those emails are being converted just fine. This is the version where we upgraded from. I guess this information doesn’t help very much.

We will keep investigating on our side what emails are affected and if we find a file that we can share we will do so as soon as possible.

@JuneTech ,

Thank you for this information. We’ll be waiting for the file you can share with us.
I’d also like to mention that the 25.10 release is expected later this week — it might potentially resolve the issue you’re facing.
Additionally, could you please confirm if you have tried performing the conversion without specifying any EmailLoadOptions?

Unfortunately, removing the EmailLoadOptions has no effect on the outcome.
We also tried the conversion with depth = 0 and then it worked, so it appears to have to do with the attachments.
As soon as 25.10 releases, we will try it.

Hello @JuneTech ,

Thank you for checking our recommendation and for sharing your observations regarding the attachments.
We’ll be waiting for your testing results with version 25.10, and hopefully, you’ll be able to locate a file that you can share with us so that we can start our investigation on our side.

Hi!
We tested with version 25.10, but have the same error here.
As these are customer mails we can’t share them with you for privacy reasons.
We tested the same with a trial license of the Aspose.Email converter and don’t have any issues there…

Hello @JuneTech ,

We are sorry to hear that version 25.10 did not fix the problem. We would really like to assist you, but without a file that you can share and that allows us to reproduce the issue, our development team will have difficulty analyzing it.
Are there any particular characteristics of the attachments in your emails—for instance, different file formats or documents containing non-text elements?
Also, could you please clarify with which version of Aspose.Email you did not experience this issue?

We thoroughly analysed some of the emails. The attachments look normal. Basic PDF files. They can be opened in Outlook, Adobe or any other PDF viewer. Also, we only encounter this issue, when we set the depth to greater than 0, i.e. when we also want to convert attachments to PDF. There is no issue with the email body itself.

With Aspose.Email we were able to unpack these email files programmatically. This worked without any issues. The version of Aspose.Email we used was 25.10.

I guess our core issue is, that converting an email is a black box for us where we have no influence over whatsoever. When the conversion fails at some point, the entire conversion is lost.

@JuneTech ,

Thank you for this information. I have created a ticket in our tracking system under the ID CONVERSIONNET-8089 and passed it to our development team.
They will try to reproduce the issue as soon as possible based on the information you provided. Unfortunately, without a test file from your side, this may be difficult.

I would also like to mention that if you decide to share a file — or if you manage to create a minimal example that reproduces the problem — please keep in mind that I had to make this topic public again. Therefore, if needed, you can send the file directly to my email: evgen.efimov@aspose.com.

As soon as I have any results from the investigation, I will let you know immediately.

Hello @JuneTech ,

Our development team attempted to reproduce this issue on their side after reviewing your use case, but unfortunately, they were unable to do so. As I mentioned earlier, investigating the problem without a specific file that reliably reproduces the error is quite challenging.

They tried creating an .eml file with an embedded .pdf, but the issue still did not occur. I’ve attached the test project they shared with me. EmlToPdf.zip (36.8 KB)

Could you please review it on your side? Perhaps you’ll spot a nuance we missed in our test project or sample file. Additionally, please confirm whether your file triggers the same issue when used with this test project.

We look forward to your updates.

Thank you very much for providing the test project. We used your setup to test it against some emails, that could not be converted on our side. There are two findings:

One type of issue is, that inside the email, another email is attached. This attached email has no further attachments. This is where we encounter one type of error.

Unhandled exception. GroupDocs.Conversion.Exceptions.CorruptOrDamagedFileException: Cannot convert. The file is corrupt or damaged. Image loading failed.
---> Aspose.Imaging.CoreExceptions.ImageLoadException: Image loading failed.
---> Aspose.Imaging.CoreExceptions.ImageLoadException: Cannot open an image. The image size can not be 0! 
[...]

It appears that there is an image embedded, that has a size of 0.

The second issue is with certain documents attached to the emails. Here we encountered this issue:

Unhandled exception. GroupDocs.Conversion.Exceptions.CorruptOrDamagedFileException: Cannot convert. The file is corrupt or damaged. Incorrect file header
 ---> Aspose.Pdf.InvalidPdfFileFormatException: Incorrect file header

We investigated the PDF file header by if the first few bytes translate to ‘%PDF-’, which they do. We also extracted each file individually and added them individually to new emails in order to find out, which file was causing the issues. However, we found out that every email could be converted. Unfortunately, we don’t have any new insight at the moment.

Hello @JuneTech ,

Thank you for sharing this information. If, as you mentioned, creating a new email with these PDF files does not lead to a conversion error, we can assume that the issue may be related to the fact that the original email was created on a different operating system and might use a different character encoding (UTF-8, Windows-1251, ISO-8859-1, etc.). There may also be differences in how the headers and metadata of the email were generated.

Could you please check the raw content of the problematic email in a text editor and compare whether there are any differences compared to the email that you recreated?

Regarding the other issue with the image in the email that has no size specified: at this moment, our library throws an exception in such scenarios, as this is the behavior defined by the current logic. Would you prefer to see a different behavior in this case? For example, simply skipping the image, or not throwing an exception but generating only a warning?

Please let us know your thoughts on this so we can forward them to our development team for further investigation.