How to convert an EML Email File to PDF Document in C# .NET Framework
2 min readJul 25, 2020
On today’s agenda: converting all of those clunky EML files you’ve got laying around into nice useful PDFs. This would normally take a multi-step process of parsing our EML into HTML, then rendering that and converting the result into PDF. None of that is easy or fun. However, I have an API that I’m going to show you that will take care of all of this for you with a single function call. Let’s look at that.
First we install our client:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8
Next we call our function with this block of code here:
using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ConvertDocumentEmlToPdfExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ConvertDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.var bodyOnly = true; // bool? | Optional; If true, the HTML string will only include the body of the email. Other information such as subject will still be given as properties in the response object. Default is false. (optional)try{// Convert Email EML file to PDF documentbyte[] result = apiInstance.ConvertDocumentEmlToPdf(inputFile, bodyOnly);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentEmlToPdf: " + e.Message );}}}}
And that’s really all that needs to be done. Easy.