Git Product home page Git Product logo

legit's Introduction

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('[email protected]')
  .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

Async/Await Usage

For a more modern approach using ES6, you can await the reponse before acting on it.

const legit = require('legit');

(async () => {
  try {
    const response = await legit('[email protected]');
    response.isValid ? console.log('valid') : console.log('invalid');
  } catch (e) {
    console.log(e);
  }
})();

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-2019 Martyn Davies, and contributors.

legit's People

Contributors

martyndavies avatar sharathm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.