How to Convert EML to JPG in Node.js

Cloudmersive
2 min readOct 16, 2023

--

We can easily create raster copies of our EML files by converting them to common image formats like JPG.

Using the below code, we can convert all our EML files to JPG image arrays (one image per page of the original file) with a free API solution. We’ll end up with a nice static version of our files which will be easy to store or share, and we can even set the output quality of our new image in the API request body.

To structure our API call, let’s begin by installing the SDK. That can be accomplished either by running this command:

npm install cloudmersive-convert-api-client --save

Or by adding this snippet to our package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

Now we should quickly get our API authorization details figured out. We can make up to 800 API calls per month with a free-tier API key — this can be obtained by registering a free account on the Cloudmersive website.

Once we have that, let’s use the below code to call the API:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();

var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.

var opts = {
'quality': 56 // Number | 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.
};

var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.convertDocumentEmlToJpg(inputFile, opts, callback);

We can customize our resulting image quality by changing 56 to any integer between 1 (lowest quality) and 100 (highest quality). Lower quality images will, of course, result in a smaller file size.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet