DEV Community

Atir Tahir
Atir Tahir

Posted on

1

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.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay