Convert an email file with attachments to PDF using C#

atir_tahir

Atir Tahir

Posted on February 3, 2020

Convert an email file with attachments to PDF using C#

There are a lot of document conversion APIs and they support Email to PDF conversion. But what about the Email (.eml or .msg) attachments?
Blow is the code to convert an Email file with attachments to PDF:

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);
}
Enter fullscreen mode Exit fullscreen mode

For further details see this post. You can also raise your concerns on forum.

💖 💪 🙅 🚩
atir_tahir
Atir Tahir

Posted on February 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related