How to validate an MSG Outlook File in Node.JS

Invalid files can easily become the Achilles heel of your project if you do not set up a means to combat the problem. When it comes to validation of Outlook’s MSG files, the problem can get even more complicated than it would be for other file formats. This is due to the potentially multi-format nature of MSG file bodies. We can dodge this landmine by using an API that is already ready to tackle this problem.

This dependency reference will allow our API client to be installed into your project.

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

The next step after that is to call validateDocumentMsgValidation through the use of an API instance, which we will create with a free key. See below.

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.ValidateDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.validateDocumentMsgValidation(inputFile, callback);

And that, ladies and gents, is how to validate MSG files in a hurry.

Image for post
Image for post

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