How to validate email addresses in Node.js

Our free API to validate e-mail addresses is really easy to use in Node.js

 

Validate e-mail in Node.js with http object


var http = require("https");

var options = {
	"method": "GET",
	"hostname": "mailcheck.p.rapidapi.com",
	"port": null,
	"path": "/?domain=DOMAIN-OR-EMAIL",
	"headers": {
		"x-rapidapi-host": "mailcheck.p.rapidapi.com",
		"x-rapidapi-key": "YOUR-API-KEY"
	}
                            };
                

This will return a JSON-array with information about the domain, and if you should block it or not.

 

Validate e-mail in Node.js with request object


var request = require("request");

var options = {
  method: 'GET',
  url: 'https://mailcheck.p.rapidapi.com/',
  qs: {domain: 'EMAIL-OR-DOMAIN'},
  headers: {
    'x-rapidapi-host': 'mailcheck.p.rapidapi.com',
    'x-rapidapi-key': 'YOUR-API-KEY'
  }
                            };

request(options, function (error, response, body) {
	if (error) throw new Error(error);

	console.log(body);
});
                

 

Verify e-mail in Node.js with axios promise based HTTP client


const axios = require("axios");

axios({
    "method":"GET",
    "url":"https://mailcheck.p.rapidapi.com/",
    "headers":{
        "content-type":"application/octet-stream",
        "x-rapidapi-host":"mailcheck.p.rapidapi.com",
        "x-rapidapi-key":"YOUR-API-KEY"
    },"params":{
       "domain":"EMAIL-OR-DOMAIN"
    }
                            })
    .then((response)=>{
       console.log(response)
    })
    .catch((error)=>{
       console.log(error)
})
                

 

You can of course just send it as a regular GET-request to that URL also, in your favorite way, as long as you have the API-key in the header.

You will receive a JSON response, telling you if this is a disposable e-mail to block, or if there are other issues with the domain:

 


{
   "valid": true,
   "block": true,
   "disposable": true,
   "domain": "mailxcdn.com",
   "text": "Disposable e-mail",
   "reason": "Blacklisted",
   "mx_host": "mail.mailxcdn.com",
   "mx_info": "Using MX pointer mail.mailxcdn.com from DNS with priority: 10",
   "mx_ip": "54.165.9.47"
}
               

This will tell you if you should block the domain mailxcdn.com or not, and the reason to why the API thinks so (disposable e-mail, etc).

To get started for free, and get an API key, click here!