Convert .eml with attachments to .pdf in C#

How can I convert an entire .eml file - with attachments - to a .pdf file? Thank you.

1 Like

@Air_Insurer,

Can you please share such an .eml file, we’ll then investigate it at our end? Also specify your development envirnoment details (Java or .NET).

Using .NET platform.

Here is a sample .eml fille … I had to change the extension to .pdf to get it to upload. If you change the extension back to .eml, it should open correctly.

Thank you!emlTE5775a.pdf (3.1 MB)

1 Like

@Air_Insurer,

Thanks for the details. Currently API doesn’t support conversion of attachments along with .eml file. But we are investigating the possibility to implement this feature. Your investigation ticket ID is CONVERSIONNET-3533. As there is any update, you’ll be notified.

@Air_Insurer,

We’ve added a feature to convert/handle email attachments in latest release of the API that is 20.1.
The following code sample shows how to convert Email document and all attachments:

var source = "sample-with-attachment.eml";
var loadOptions = new EmailLoadOptions {ConvertAttachments = true};
using (var converter = new Converter(source, () => loadOptions))
{
    var index = 1;
    var options = new PdfConvertOptions();
    // Note: index = 1 is the email itself, all following indexes are attachments
    converter.Convert(() => new FileStream($"converted-{index++}.pdf", FileMode.Create) , options);
}

This feature covers exactly what I was looking for!
It’s working very well in our test scenarios with multiple different attachment types but I haven’t found a way to configure the conversion for type specific settings, e.g. spreadsheet attachment should not be converted as single page PDFs which is the default for that type of conversion.

Is it possible to configure the attachment conversion depending on the attachment file type in your example - index 1 would be the email itself, index 2 is a jpg file and index 3 would be an xlsx file?

var source = “sample-with-attachment.eml”;
var loadOptions = new EmailLoadOptions {ConvertAttachments = true};
using (var converter = new Converter(source, () => loadOptions))
{
var index = 1;
var options = new PdfConvertOptions();
// Note: index = 1 is the email itself, all following indexes are attachments
converter.Convert(() => new FileStream($“converted-{index++}.pdf”, FileMode.Create) , options);
}

Thank you.

1 Like

@JBbadk,

Your query is answered here.

A post was merged into an existing topic: EML file with attachments to 1 PDF