How to Convert EML to JPG in C# .Net Framework

Cloudmersive
2 min readAug 5, 2020

--

Parsing and converting EML files is quite a task for the unprepared. To break it down for you, first you need to filter the HTML out of the EML file itself, render that, rasterize to an image, and save it as a JPG. All of this is quite difficult to deal with, especially when all combined together. As a nice, easy alternative, today’s post will cover how to do this in a single function call.

First, we use this command for the Package Manger console to install our API client.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8

And now it’s time for the aforementioned function call.

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 ConvertDocumentEmlToJpgExample{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 quality = 56;  // int? | Optional; Set the JPEG quality level; lowest quality is 1 (highest compression), highest quality (lowest compression) is 100; recommended value is 75. Default value is 75. (optional)try{// Convert Email EML file to JPG/JPEG image arrayEmlToJpgResult result = apiInstance.ConvertDocumentEmlToJpg(inputFile, quality);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentEmlToJpg: " + e.Message );}}}}

And you are done!

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.