Socket
Book a DemoInstallSign in
Socket

legit

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

legit

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

2.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Legit

BREAKING CHANGE NOTICE (v2.0.0): Legit has been migrated to TypeScript. This introduces a breaking change in how the module is imported. Please update your code to use ES module imports (import legit from 'legit') instead of require.

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

import legit from "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 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 response before acting on it.

import legit from "legit";

(async () => {
  try {
    const response = await legit("validemail@validdomain.com");
    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-2025 Martyn Davies, and contributors.

Keywords

email

FAQs

Package last updated on 01 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.