How to convert an MSG Outlook File to HTML String in Node.JS

Outlook’s MSG files can be very inconvenient to work with, so today we will be looking at an option for quickly converting from this format into an HTML string. While this would normally take hours to get running properly, I am going to show you the ultra-easy way to do it using an API.

Let’s get our client installed first.

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

And then our function call looks like this:

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 MSG. Other information such as subject will still be given as properties in the response object. Default is false.'includeAttachments': true // Boolean | Optional; If false, the response object will not include any attachment files from the input file. Default is true.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentMsgToHtml(inputFile, opts, callback);

You may use the optional bools to specify if you would like to keep the attachment files as byte arrays, as well as whether you want only the body of the email in your main response. And that’s all that needs to be said, since the API will handle the rest. Easy.

Image for post
Image for post

Written by

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