Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including legit with all npm packages installed. Try it out:

var legit = require("legit")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

legit v1.0.5

Check that email addresses are really able to accept emails by pinging the DNS and checking for active MX records.

Legit

Travis CI

A wrapper for the NodeJS Dns.resolveMx method that checks the domain of an email address for valid/existence of MX records.

Installation

$ npm install legit

Usage

const legit = require("legit");

legit("validemail@validdomain.com")
  .then(result => {
    result.isValid ? console.log("Valid!") : console.log("Invalid!");
    console.log(JSON.stringify(result));
  })
  .catch(err => console.log(err));

If an email addresses domain is legit then the object returned will include an isValid key that will be set to true as well as an mxArray key with all the MX record information for the valid domain.

If the domain has no MX or cannot resolve any MX then it will return isValid as false.

Anything else is considered an error and you'll get it in the .catch

Example Response

For a valid email address, you'll get the following response object:

{
   "isValid":true,
   "mxArray":[
      {
         "exchange":"aspmx.l.google.com",
         "priority":1
      },
      {
         "exchange":"alt1.aspmx.l.google.com",
         "priority":5
      },
      {
         "exchange":"alt2.aspmx.l.google.com",
         "priority":5
      },
      {
         "exchange":"alt3.aspmx.l.google.com",
         "priority":10
      },
      {
         "exchange":"alt4.aspmx.l.google.com",
         "priority":10
      }
   ]
}

License

(The MIT License)

Copyright (c) 2015-2018 Martyn Davies, and contributors.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free