How to convert an EML Email File to HTML String in C# .NET Framework
2 min readJul 25, 2020
EML format can be a bit tricky to work with in many situations. Having it parsed out for you into neat HTML is generally much more handy. Today we will be handling this nicely with an API that is built for the task. This will give us high fidelity results as well as keep the time required to a minimum.
First we need to install our package using NuGet:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8
Next we can input our EML file into this function:
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 ConvertDocumentEmlToHtmlExample{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)var includeAttachments = true; // bool? | Optional; If false, the response object will not include any attachment files from the input file. Default is true. (optional)try{// Convert Email EML file to HTML stringEmlToHtmlResult result = apiInstance.ConvertDocumentEmlToHtml(inputFile, bodyOnly, includeAttachments);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentEmlToHtml: " + e.Message );}}}}
And that’s it! Done.