email-domain-verifier
A npm package that verifies email domains via dns mx records and attempting smtp connection
Installation
npm install email-domain-verifier --save
Usage
import { verifyEmailDomain } from 'email-domain-verifier'
await verifyEmailDomain('mailbox@gmail.com', { requireSmtpOrMx: true })
await verifyEmailDomain('mailbox@garbage.domain', { requireSmtpOrMx: true })
Options
{
mxNotRequired?: boolean,
smtpNotRequired?: boolean,
requireSmtpOrMx?: boolean,
smtpConnectionTimeout?: number,
useCache?: boolean
}
Details
Cache
- Simple in-memory lru cache
- Verification with
{ useCache: false }
doesn't fetch cache, but still updates it - Only successful verifications get stored in cache
- Max cache size is 1000 and ttl is 24 hours
Smtp check
- Conducted via attempting tcp connection to popular smtp ports
- Ports list is
[ 25, 456, 587, 2525 ]
- The check is successful if at least one of these ports is open on any of the mail exchange servers
- In addition to mail exchange servers, these ports are scanned on
`${domain}` and `smtp.${domain}`
- Most public ISP block requests to port 25, so port 25 scan might not work from your home, but should work from your server
Mx check
- The check is successful if domain has at least one mx record
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
MIT