How to validate an EML Email File in Node.JS

Validation is your best friend when working with large numbers of files, especially when user error comes into play. Getting this validation up and running is not an easy process; from start to finish, a setup from scratch is going to take hours to get working. Instead, I will show you a way to validate your EML files in double quick time using an API that I have set up for just this situation.

Node.JS users can import the client by adding the following reference into your package json file.

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

And now we are going to input our file data into validateDocumentEmlValidation, which we will run using an instance of the Validate Document API. Look through this example for how to set this all up.

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

And once you run it, you will receive an object response which tells you if the file is a valid EML. If not, it will also include a list of errors that invalidate it.

Image for post
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