email-validator-ultimate
v2.1.0
Published
Advanced email validation library for Node.js. RFC 5322 format validation, MX records, SMTP inbox check, disposable email detection, typo suggestions, risk analysis, Gravatar detection, DNS blacklist check, batch validation, caching, and CLI tool.
Maintainers
Keywords
Readme
Overview
Email Validator Ultimate is a powerful, enterprise-grade email validation library that goes far beyond simple regex checks. It provides comprehensive validation including format verification, DNS/MX record lookup, SMTP inbox testing, disposable email detection, risk analysis, and much more.
Why Choose Email Validator Ultimate?
| Feature | Basic Validators | Email Validator Ultimate | |---------|------------------|--------------------------| | RFC 5322 Format Check | Partial | Full | | MX Record Validation | No | Yes | | SMTP Inbox Check | No | Yes | | Disposable Email Detection | No | Yes (150+ domains) | | Typo Suggestions | No | Yes | | Risk Analysis | No | Yes | | Email Normalization | No | Yes | | Gravatar Detection | No | Yes | | DNS Blacklist Check | No | Yes | | Batch Validation | No | Yes | | CLI Tool | No | Yes | | Caching | No | Yes | | TypeScript Support | Varies | Full |
Table of Contents
- Installation
- Quick Start
- Features
- CLI Tool
- API Reference
- TypeScript Support
- Best Practices
- Contributing
- License
Installation
# Using npm
npm install email-validator-ultimate
# Using yarn
yarn add email-validator-ultimate
# Using pnpm
pnpm add email-validator-ultimateGlobal CLI Installation
npm install -g email-validator-ultimateQuick Start
ES Modules (ESM)
import { validateEmail } from 'email-validator-ultimate';
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]'
});
console.log(result.qualityScore); // 100
console.log(result.isValid); // trueCommonJS
const { validateEmail } = require('email-validator-ultimate');
async function validate() {
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]'
});
console.log(result);
}
validate();Features
Basic Validation
The core validateEmail function performs comprehensive checks on an email address.
import { validateEmail } from 'email-validator-ultimate';
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]',
smtpCheck: false, // Enable SMTP validation
cache: true // Enable caching for better performance
});Result Object:
{
email: '[email protected]',
username: 'user',
domain: 'gmail.com',
formatValid: true,
hasMX: true,
isDisposable: false,
isGeneric: false,
isFree: true,
provider: 'Gmail',
mxRecord: 'gmail-smtp-in.l.google.com',
canReceiveEmail: {
smtpSuccess: false,
message: 'SMTP check skipped',
catchAll: false
},
qualityScore: 100,
suggestion: null
}Batch Validation
Validate multiple emails efficiently with concurrency control.
import { validateEmails } from 'email-validator-ultimate';
const result = await validateEmails({
emails: [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]'
],
fromEmail: '[email protected]',
concurrency: 10, // Process 10 emails at a time
onProgress: (completed, total) => {
console.log(`Progress: ${completed}/${total}`);
}
});
console.log(`Valid: ${result.valid} / ${result.total}`);
console.log(`Average Score: ${result.summary.averageScore}`);Batch Result:
{
total: 4,
valid: 3,
invalid: 1,
processingTime: 1250,
summary: {
validFormat: 4,
invalidFormat: 0,
hasMX: 4,
noMX: 0,
disposable: 1,
generic: 1,
freeProvider: 2,
averageScore: 75
},
results: [...] // Individual results
}Email Normalization
Normalize email addresses by removing dots, plus aliases, and standardizing domains.
import { normalizeEmail, areEmailsEquivalent } from 'email-validator-ultimate';
// Gmail ignores dots and supports plus aliases
const result = normalizeEmail('[email protected]');
console.log(result.normalized); // '[email protected]'
// Check if two emails are the same person
const same = areEmailsEquivalent(
'[email protected]',
'[email protected]'
);
console.log(same); // trueNormalization Result:
{
original: '[email protected]',
normalized: '[email protected]',
wasModified: true,
localPart: 'john',
domain: 'gmail.com',
removedAlias: 'newsletter'
}Risk Analysis
Detect suspicious patterns that may indicate fake, bot, or spam accounts.
import { analyzeRisk, isHighRisk } from 'email-validator-ultimate';
// Analyze email for risk patterns
const risk = analyzeRisk('[email protected]');
console.log(risk.riskLevel); // 'high'
console.log(risk.riskScore); // 65
console.log(risk.isHighRisk); // true
console.log(risk.factors); // Array of detected risk factorsRisk Factors Detected:
| Pattern | Description | Severity |
|---------|-------------|----------|
| KEYBOARD_PATTERN | Contains patterns like "qwerty", "12345" | Medium |
| RANDOM_STRING | Appears randomly generated | High |
| ALL_NUMBERS | Local part is only numbers | High |
| UUID_PATTERN | Contains UUID-like strings | High |
| SUSPICIOUS_TLD | Uses TLD associated with spam | High |
| TOO_SHORT | Very short local part | Medium |
| CONSECUTIVE_CHARS | 5+ repeated characters | High |
Typo Suggestions
Automatically detect and suggest corrections for common email typos.
import { getEmailSuggestion, getSuggestedEmail } from 'email-validator-ultimate';
// Get detailed suggestion
const suggestion = getEmailSuggestion('[email protected]');
console.log(suggestion);
// {
// hasSuggestion: true,
// suggested: '[email protected]',
// domain: { original: 'gmial.com', suggested: 'gmail.com' }
// }
// Quick correction
const corrected = getSuggestedEmail('[email protected]');
console.log(corrected); // '[email protected]'Supported Typo Corrections:
- Gmail: gmial, gmal, gmaill, gnail, gamil, gmail.con
- Yahoo: yaho, yahooo, yhaoo, yahoo.con
- Hotmail: hotmal, hotmial, htmail, hotnail
- Outlook: outlok, outllok, outlook.con
- iCloud: iclod, icould, icloud.con
- TLDs: .con → .com, .ent → .net, .ogr → .org
Gravatar Detection
Check if an email has an associated Gravatar profile (indicates established user).
import { checkGravatar, hasGravatar } from 'email-validator-ultimate';
// Full Gravatar check
const gravatar = await checkGravatar('[email protected]');
console.log(gravatar);
// {
// hasGravatar: true,
// gravatarUrl: 'https://www.gravatar.com/avatar/...',
// profileUrl: 'https://www.gravatar.com/...',
// hash: 'abc123...',
// profile: { displayName: 'John Doe', ... }
// }
// Quick check
const exists = await hasGravatar('[email protected]');
console.log(exists); // trueDNS Blacklist Check
Check if a domain's mail servers are listed in spam blacklists.
import { checkBlacklist, isBlacklisted } from 'email-validator-ultimate';
// Full blacklist check
const blacklist = await checkBlacklist('suspicious-domain.com');
console.log(blacklist);
// {
// domain: 'suspicious-domain.com',
// isBlacklisted: true,
// listedIn: ['zen.spamhaus.org', 'bl.spamcop.net'],
// reputationScore: 35,
// mxServers: ['10.20.30.40']
// }
// Quick check
const listed = await isBlacklisted('example.com');
console.log(listed); // falseDisposable Email Detection
Detect temporary/throwaway email addresses with 150+ known disposable domains.
import {
isDisposable,
addDisposableDomains,
addToWhitelist
} from 'email-validator-ultimate';
// Check if disposable
const disposable = await isDisposable('[email protected]');
console.log(disposable); // true
// Add custom disposable domains
addDisposableDomains(['custom-temp.com', 'another-temp.org']);
// Whitelist domains that should never be marked disposable
addToWhitelist(['mycompany-temp.com']);SMTP Validation
Test if an email inbox actually exists by connecting to the mail server.
import { validateEmail } from 'email-validator-ultimate';
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]',
smtpCheck: true, // Enable SMTP validation
debug: true // See SMTP conversation
});
console.log(result.canReceiveEmail);
// {
// smtpSuccess: true,
// inboxExists: true,
// catchAll: false,
// message: 'Valid inbox (no catch-all)'
// }Requirements:
- Server must allow outbound port 25
- Valid sender email address
- Some servers may block or rate-limit
Quality Scoring
Get an intelligent quality score (0-100) based on multiple factors.
import { validateEmail, getScoreDescription } from 'email-validator-ultimate';
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]'
});
console.log(result.qualityScore); // 100
console.log(getScoreDescription(result.qualityScore)); // 'Excellent'Score Calculation:
| Factor | Impact | Description | |--------|--------|-------------| | Invalid Format | Score = 0 | Hard fail | | No MX Record | -40 | Cannot receive email | | SMTP Failed | -30 | Inbox doesn't exist | | Disposable | -20 | Temporary email | | Generic Username | -10 | Role-based (admin, info) | | Catch-All Domain | -5 | Accepts any address |
Score Interpretation:
| Score | Rating | Action | |-------|--------|--------| | 90-100 | Excellent | Safe to use | | 70-89 | Good | Generally reliable | | 50-69 | Fair | Use with caution | | 30-49 | Poor | High risk | | 0-29 | Very Poor | Reject |
Caching
Built-in LRU cache for improved performance on repeated validations.
import { validateEmail, clearCache, getGlobalCache } from 'email-validator-ultimate';
// Enable caching
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]',
cache: true
});
// Second call is instant (cached)
const cached = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]',
cache: true
});
// View cache stats
console.log(getGlobalCache().stats());
// { size: 1, maxSize: 1000, ttl: 300000 }
// Clear when needed
clearCache();CLI Tool
Email Validator Ultimate includes a powerful command-line interface.
Installation
npm install -g email-validator-ultimateCommands
# Validate single email
email-validator-ultimate validate [email protected]
# Or use the short alias
evu validate [email protected]
# Quick validation (format + MX only)
evu quick [email protected]
# Batch validation from file
evu batch emails.txt --json > results.json
# Normalize email
evu normalize "[email protected]"
# Risk analysis
evu risk [email protected]
# Check Gravatar
evu gravatar [email protected]
# Check blacklists
evu blacklist suspicious-domain.com
# Typo suggestions
evu suggest [email protected]
# With SMTP check
evu validate [email protected] --smtp --from [email protected]
# JSON output
evu validate [email protected] --jsonCLI Output Example
╔═══════════════════════════════════════════════════════════╗
║ Email Validator Ultimate v2.1.0 ║
║ Advanced Email Validation Tool ║
╚═══════════════════════════════════════════════════════════╝
Validating: [email protected]
──────────────────────────────────────────────────────
• Email: [email protected]
✓ Format Valid: true
✓ Has MX Record: true
✓ Is Disposable: false
✓ Is Generic: false
• Is Free Provider: true
• Provider: Gmail
• MX Record: gmail-smtp-in.l.google.com
Quality Score:
██████████ 100/100API Reference
Main Functions
| Function | Description |
|----------|-------------|
| validateEmail(options) | Comprehensive single email validation |
| validateEmails(options) | Batch validation with concurrency |
| quickValidate(email) | Fast validation (format + MX only) |
| validateWithPreset(email, from, preset) | Validate using presets |
| validateEmailComprehensive(email, from) | Full validation with all checks |
Utility Functions
| Function | Description |
|----------|-------------|
| normalizeEmail(email) | Normalize email address |
| areEmailsEquivalent(email1, email2) | Check if emails are same person |
| analyzeRisk(email) | Get risk analysis |
| checkGravatar(email) | Check Gravatar profile |
| checkBlacklist(domain) | Check DNS blacklists |
| getEmailSuggestion(email) | Get typo suggestion |
| isDisposable(email) | Check if disposable |
| isGeneric(username) | Check if generic username |
| getQualityScore(factors) | Calculate quality score |
Configuration Functions
| Function | Description |
|----------|-------------|
| addDisposableDomains(domains) | Add disposable domains |
| removeDisposableDomains(domains) | Remove disposable domains |
| addToWhitelist(domains) | Whitelist domains |
| setGenericUsernames(usernames) | Set generic usernames |
| clearCache() | Clear validation cache |
TypeScript Support
Full TypeScript support with exported types.
import {
validateEmail,
ValidateOptions,
ValidationResult,
RiskAnalysisResult,
GravatarResult,
BlacklistResult,
NormalizeResult
} from 'email-validator-ultimate';
const options: ValidateOptions = {
email: '[email protected]',
fromEmail: '[email protected]',
smtpCheck: true,
cache: true
};
const result: ValidationResult = await validateEmail(options);Best Practices
1. Use Caching in Production
const result = await validateEmail({
email: '[email protected]',
fromEmail: '[email protected]',
cache: true // Always enable in production
});2. Use Appropriate Validation Level
// For sign-up forms (quick response)
const quick = await quickValidate(email);
// For important operations (comprehensive)
const full = await validateEmail({ email, fromEmail, smtpCheck: true });3. Handle Suggestions in UI
const result = await validateEmail({ email, fromEmail });
if (result.suggestion) {
// Show user: "Did you mean [email protected]?"
showSuggestion(result.suggestion.suggested);
}4. Batch Processing
// Use appropriate concurrency based on your server
const result = await validateEmails({
emails: largeList,
fromEmail: '[email protected]',
concurrency: 5, // Don't overwhelm mail servers
skipDisposableCheck: true // Skip API calls for speed
});Express.js Integration
const express = require('express');
const { validateEmail, validateEmails } = require('email-validator-ultimate');
const app = express();
app.use(express.json());
// Single validation endpoint
app.post('/api/validate', async (req, res) => {
try {
const result = await validateEmail({
email: req.body.email,
fromEmail: '[email protected]',
cache: true
});
res.json({
valid: result.formatValid && result.hasMX && !result.isDisposable,
score: result.qualityScore,
suggestion: result.suggestion?.suggested
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Batch validation endpoint
app.post('/api/validate-batch', async (req, res) => {
const result = await validateEmails({
emails: req.body.emails,
fromEmail: '[email protected]',
concurrency: 10
});
res.json(result);
});
app.listen(3000);Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
Changelog
v2.1.0
- Added email normalization (Gmail dots, plus aliases)
- Added risk pattern analysis
- Added Gravatar detection
- Added DNS blacklist checking
- Added CLI tool with multiple commands
- Expanded disposable domains to 150+
- Added whitelist functionality
- Added comprehensive validation function
v2.0.0
- RFC 5322 compliant format validation
- Email typo suggestions
- Batch validation with concurrency
- LRU caching support
- Validation presets
- Full TypeScript definitions
v1.0.0
- Initial release
License
MIT License - see the LICENSE file for details.
Author
Aminul Islam (Mehedi Hasan)
- Email: [email protected]
- GitHub: @ai-mehedi
