All Projects → martyndavies → legit

martyndavies / legit

Licence: MIT license
NodeJS library for checking MX records exist on a domain

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to legit

prowide-iso20022
Comprehensive business model and parser for all ISO 20022 messages
Stars: ✭ 75 (-31.82%)
Mutual labels:  mx
email-checker
Provides email verification on the go.
Stars: ✭ 116 (+5.45%)
Mutual labels:  mx-record
HostSpider
Domain information gathering tool
Stars: ✭ 61 (-44.55%)
Mutual labels:  mx-record
port25-bouncehandler
Port25 PowerMTA bounce handler for Interspire and MailWizz
Stars: ✭ 66 (-40%)
Mutual labels:  mx-record
MailDemon
Smtp server for mass emailing, managing email lists and more. Built on .NET Core. Linux, MAC and Windows compatible.
Stars: ✭ 113 (+2.73%)
Mutual labels:  mx-record

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].