E-mail validation: Validate e-mail addresses using NodeJS

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 948 All time: 10 This week: 3Up
Version License JavaScript version Categories
email-validation 1.0.6BSD License1.0Validation, E-mail, Node.js
Description 

Author

This object can be used to validate an e-mail address by using NodeJS to check with an SMTP server.

It can connect to check if the e-mail domain has valid MX.

If the MX records do not exist, it falls back to resolving the domain A record to determine the e-mail address domain SMTP server addresses.

The object attempts to validate the e-mail address by simulating a delivery of a message to the domain SMTP server.

When it reaches a conclusion the object calls a given callback function with the result, which can be whether the address is valid, invalid or undetermined.

Picture of Manuel Lemos
  Performance   Level  
Name: Manuel Lemos <contact>
Classes: 11 packages by
Country: Portugal Portugal
Age: 55
All time rank: 21 in Portugal Portugal
Week rank: 6 Down1 in Portugal Portugal Equal

Example

/*jslint node: true, sloppy: true, white: true */ /* * testEmailValidation.php * * @(#) $Id: testEmailValidation.js,v 1.4 2014/04/05 12:10:27 mlemos Exp $ * */ var email, validation, emailValidation; if(process.argv.length < 3) { console.log('It was not specified the e-mail address for validation.'); } else { /* * Load the e-mail validation module */ emailValidation = require('./emailValidation'); /* * Configure the path of the sockets module */ emailValidation.socketsModule = './sockets'; var validation = new emailValidation.validation(); /* * E-mail address of local user to simulate e-mail delivery */ validation.localAddress = 'localuser@localhost'; /* * Output debug information */ validation.debug = true; /* * Output debug information about network socket communication */ validation.debugSockets = false; /* * Function to output debug information */ validation.debugOutput = console.log; /* * Timeout for network socket communication in seconds */ validation.timeout = 15; var email = process.argv[2]; validation.emailDomainsWhitelistFile = 'emaildomainswhitelist.csv'; validation.invalidEmailUsersFile = 'invalidemailusers.csv'; validation.invalidEmailDomainsFile = 'invalidemaildomains.csv'; validation.invalidEmailServersFile = 'invalidemailservers.csv'; validation.validate(email, function (result) { if(result.valid === undefined) { console.log('Error: ' + result.error); } else { if(result.valid === null) { console.log('It was not possible to determine whether the address ' + email + ' is valid' + (result.error ? ': ' + result.error : '.')); } else { console.log('The address ' + email + ' is ' + (result.valid ? 'valid' : 'invalid') + '.'); if(!result.valid && result.status === validation.EMAIL_VALIDATION_STATUS_TYPO_IN_DOMAIN) { console.log('It may be a typing mistake. The correct email address may be ' + result.suggestions[0] + ' .'); } } } }); }

  Files folder image Files (6)  
File Role Description
Accessible without login Plain text file testEmailValidation.js Example Script to test the e-mail validation object from the command line
Accessible without login Plain text file emaildomainswhitelist.csv Data White list of domains to always be considered valid
Plain text file emailValidation.js Class NodeJS module to validate an e-mail address
Accessible without login Plain text file invalidemaildomains.csv Data Sample list of domains known to be invalid for email addresses
Accessible without login Plain text file invalidemailservers.csv Data Invalid email servers list
Accessible without login Plain text file invalidemailusers.csv Data List of invalid email address user names

Downloademail-validation-2014-04-08.zip 6KB
Downloademail-validation-2014-04-08.tar.gz 5KB
Needed packages  
Class DownloadWhy it is needed Dependency
NodeJS Network Sockets Download .zip .tar.gz Makes the actual communication with the SMTP servers Required
 Version Control Unique User Downloads Download Rankings  
 33%
Total:948
This week:0
All time:10
This week:3Up