How to convert an EML Email File to PDF Document in Node.JS

Converting EML files into simple PDF documents can really make life a lot easier. I know how difficult this process can be, so I have set up an API for you to use that will speed you straight through to the results. From beginning to end, this will only require minute of your time.

With npm install, our client can be imported with this command:

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

And moving right along, we will be calling the function convertDocumentEmlToPdf next. This will require us to use an API instance, but don’t worry, I’ve got the details on that in the example code here:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'bodyOnly': true // Boolean | 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.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentEmlToPdf(inputFile, opts, callback);

Now you may add your input file, and specify whether you would like to include header information (e.g. To and From) in your final PDF using the bodyOnly bool. And that’s it!

Image for post

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store