mfbx9da4 / deep-email-validator

Validates regex, typos, disposable, dns and smtp
MIT License
861 stars 87 forks source link
email-validation email-validator smtp

Email Validator

Validates email addresses based on regex, common typos, disposable email blacklists, DNS records and SMTP server response.

Getting Started

Compatible with nodejs only. Not browser ready.

Install like so

npm i deep-email-validator --save

or with yarn

yarn add deep-email-validator

Use like so

import { validate } from 'deep-email-validator'
const main = async () => {
  let res = await validate('asdf@gmail.com')
  // {
  //   "valid": false,
  //   "reason": "smtp",
  //   "validators": {
  //       "regex": {
  //         "valid": true
  //       },
  //       "typo": {
  //         "valid": true
  //       },
  //       "disposable": {
  //         "valid": true
  //       },
  //       "mx": {
  //         "valid": true
  //       },
  //       "smtp": {
  //         "valid": false,
  //         "reason": "Mailbox not found.",
  //       }
  //   }
  // }

  // Can also be called with these default options
  await validate({
    email: 'name@example.org',
    sender: 'name@example.org',
    validateRegex: true,
    validateMx: true,
    validateTypo: true,
    validateDisposable: true,
    validateSMTP: true,
  })
}

If you want to validate domains with TLDs that are not supported by default, you can use additionalTopLevelDomains option:

await validate({
  email: 'name@example.ir',
  sender: 'name@example.ir',
  validateRegex: true,
  validateMx: true,
  validateTypo: true,
  validateDisposable: true,
  validateSMTP: true,
  additionalTopLevelDomains: [ 'ir' ]
})

For a list of TLDs that are supported by default you can see here.

Default options can be found here