How to convert an MSG Outlook File to a PDF Document in Node.JS

MSG files are notoriously difficult to work with where compatibility and convenience are concerned. They have multiple formats just for their body content, which can really make parsing them into a small nightmare. For that reason, we are going to be skipping the manual method for this task, instead opting for the easiest method possible: an API.

Our installation will come first, using this reference for our package.json.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"

Next we are going to call our function for the conversion from MSG to PDF. You can look at this reference code to see how that will work:

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.convertDocumentMsgToPdf(inputFile, opts, callback);

Alright, time to pop those champagne corks, because we are officially done! Seriously, that is just how simple this process can be with an API.

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