MailConfirm
A Node Js API for three stage email validation including the following;
- email pattern validation,
- MX mail server existence,
- mailbox existence.
NOTE: True mailbox existence may only be performed, with certainty, by sending a verification email and having the user verify their email.
Install
yarn add mail-confirm
npm i mail-confirm
Usage
Usage Notes
- Ensure you execute this in an environment where SMTP port 25 is accessible. Failing to do so will throw error Mailbox check failed.
- Internal instance methods are exposed as Static methods. If you wish to build your own email verification routine, or only require one of these staged methods, simply call MailConfirm.[methodName]. See API Documentation below.
import MailConfirm from 'mail-confirm'
const email = new MailConfirm({
emailAddress: 'test@gmail.com',
timeout: 2000,
mailFrom: 'my@email.com',
invalidMailboxKeywords: ['noreply', 'noemail']
})
email.check().then(console.log).catch(console.log)
const check = async (emailAddress) => {
try{
const email = new MailConfirm({ emailAddress })
const result = await email.check()
return result
}catch(err){
throw new Error(err)
}
}
check('test@gmail.com')
API Documentation
MailConfirm
Kind: global class
new MailConfirm(config)
Email address validation and SMTP verification API.
Param | Type | Description |
---|
config | Object | The email address you want to validate. |
config.emailAddress | string | The email address you want to validate. |
[config.mailFrom] | string | The email address used for the mail from during SMTP mailbox validation. |
[config.invalidMailboxKeywords] | Array.<string> | Keywords you want to void, i.e. noemail, noreply etc. |
[config.timeout] | number | The timeout parameter for SMTP mailbox validation. |
mailConfirm.check() ⇒ Object
Runs the email validation routine and supplies a final result.
Kind: instance method of MailConfirm
Returns: Object
- - The instance state object containing all of the isValid* boolean checks, MX Records, and SMTP Messages.
MailConfirm.resolvePattern(emailAddress, [invalidMailboxKeywords]) ⇒ boolean
Determines if the email address pattern is valid based on regex and invalid keyword check.
Kind: static method of MailConfirm
Param | Type | Default | Description |
---|
emailAddress | string | | The full email address ypu want to check. |
[invalidMailboxKeywords] | Array.<string> | [] | An array of keywords to invalidate your check, ie. noreply |
, noemail, etc. | | | |
MailConfirm.resolveMx(hostname) ⇒ Array.<Object>
Wrap of dns.resolveMx native method.
Kind: static method of MailConfirm
Returns: Array.<Object>
- - Returns MX records array { priority, exchange }
Param | Type | Description |
---|
hostname | string | The hostname you want to resolve, i.e. gmail.com |
MailConfirm.resolveSmtpMailbox(config) ⇒ Array.<object>
Runs the SMTP mailbox check. Commands for HELO/EHLO, MAIL FROM, RCPT TO.
Kind: static method of MailConfirm
Returns: Array.<object>
- - Object of SMTP responses [ {command, status, message} ]
Param | Type | Description |
---|
config | Object | Object of parameters for Smtp Mailbox resolution. |
config.emailAddress | string | The email address you want to check. |
config.mxRecords | Array.<object> | The MX Records array supplied from resolveMx. |
config.timeout | number | Timeout parameter for the SMTP routine. |
config.mailFrom | string | The email address supplied to the MAIL FROM SMTP command. |
Title: MailConfirm
Author: Elias Hussary eliashussary@gmail.com
License: MIT
Copyright: (C) 2017 Elias Hussary