art-email-validator
Art.Email.Validator
Last updated 2 years ago by shanebdavis .
ISC · Original npm · Tarball · package.json
$ cnpm install art-email-validator 
SYNC missed versions from official npm registry.

Art.Email.Validator

Validate email and suggest corrections. Steps:

  1. check the domain syntactically - just a rough, quick-check
  2. look up the MX record for the domain, fail if it doesn't exist
  3. communciate with the SMTP server on the MX-server to determine if the mailbox exists
  4. if the SMTP server responds ambiguously, optiontionally, invoke fallbackValidator - useful to call an external, premium validation service

Always returns a results-object regardless of what happens, example output:

  • valid: true/false
  • invalid: true/false
  • didYouMean: '...@...'
  • message: 'details about what happend'

Install

npm install art-email-validator

Usage

&ArtEmailValidator.validateEmail
  email:    "foobar@gmailcom"         # email to check
  smtpHost: "my.domain.com"           # your domain, the same every call
.then (results) ->

# Example output:
results =
  valid:      false                   # possibly invalid
  invalid:    true                    # definitly invalid
  didYouMean: "foobar@gmail.com"      # suggested fix
  message:    "Domain was not valid." # developer-friendly info

API

&ArtEmailValidator.validateEmail options
.then (results) ->

# NOTE: &ArtEmailValidator means: require('art-email-validator')

options<object>

  • email<string> (required) the email address to check
  • smtpFrom<string> (required OR smtpHost) the smtpFrom-address to tell the email server [default: email]
  • smtpHost<string> (required OR smtpFrom) the smtpHost to tell the email server [default: the domain of part of: smtpFrom]
  • timeout<number-milliseconds> (default: 1000) number in miliseconds to wait before timing out when checking mailbox
  • fallbackValidator<(options, results) -> results> Called as the very last step if validateMailbox can't conclusively determine if it is valid. Example: use this to call Mailgun's email validation service.
  • verbose<bool/number> (default: false) verbose: true ==> basic verbos logging, verbose: >= 2 ==> very verbose logging

results<object>

  • valid<bool> 'true' means the email is definitly valid
  • invalid<bool> 'true' means email is definitly invalid
  • didYouMean<string> (optional) suggest a possibly-correct email
  • message<string> developer-consumable description of what happened

Note, the result is ambiguous if valid == false, but invalid != true. This indicates the SMTP server failed to respond in a known way and there was no fallbackValidator.

Trivia

Current Tags

  • 1.2.2                                ...           latest (2 years ago)

4 Versions

  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 2
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |