Skip to main content

Email Validation Tool

Real-time email validation with SMTP verification, disposable email detection, and typo correction.

🎯 What is Email Validation?​

Email validation verifies email addresses in real-time to ensure they're valid, deliverable, and not from disposable email services. It helps improve data quality and reduces bounce rates.

βš™οΈ Setup & Configuration​

Basic Implementation​

const validateEmail = async (email, secretKey) => {
try {
const response = await fetch('https://api.trustedaccounts.org/email/validate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${secretKey}`
},
body: JSON.stringify({
email: email,
options: {
validateSMTP: true, // Real-time SMTP validation
validateMX: true, // Check MX records
checkDisposable: true, // Detect disposable emails
checkTypo: true // Detect typos and suggest corrections
}
})
});

const result = await response.json();
return result;
} catch (error) {
console.error('Email validation failed:', error);
return { valid: false, reason: 'Validation service unavailable' };
}
};

// Usage
validateEmail('user@example.com', 'YOUR_SECRET_KEY').then(result => {
if (result.valid) {
console.log('Email is valid:', result);
} else {
console.log('Email validation failed:', result.reason);
if (result.suggestions) {
console.log('Suggestions:', result.suggestions);
}
}
});

Advanced Configuration​

const validateEmailAdvanced = async (email, secretKey, options = {}) => {
const defaultOptions = {
validateSMTP: true,
validateMX: true,
checkDisposable: true,
checkTypo: true,
checkRole: true, // Detect role-based emails (admin@, info@)
checkFree: true, // Detect free email providers
timeout: 10000 // 10 second timeout
};

const validationOptions = { ...defaultOptions, ...options };

try {
const response = await fetch('https://api.trustedaccounts.org/email/validate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${secretKey}`
},
body: JSON.stringify({
email: email,
options: validationOptions
})
});

return await response.json();
} catch (error) {
console.error('Email validation failed:', error);
return { valid: false, reason: 'Validation service unavailable' };
}
};

πŸ“§ Batch Validation​

Validate multiple emails at once for better performance:

const validateEmails = async (emails, secretKey) => {
try {
const response = await fetch('https://api.trustedaccounts.org/email/validate-batch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${secretKey}`
},
body: JSON.stringify({
emails: emails,
options: {
validateSMTP: true,
validateMX: true,
checkDisposable: true,
checkTypo: true
}
})
});

const results = await response.json();
return results;
} catch (error) {
console.error('Batch validation failed:', error);
return { error: 'Validation service unavailable' };
}
};

// Usage
const emails = ['user1@example.com', 'user2@example.com', 'invalid@email'];
validateEmails(emails, 'YOUR_SECRET_KEY').then(results => {
results.forEach((result, index) => {
console.log(`Email ${index + 1}: ${result.valid ? 'Valid' : 'Invalid'}`);
});
});

πŸ”§ Server-Side Integration​

Node.js/Express Example​

app.post('/api/validate-email', async (req, res) => {
const { email } = req.body;
const secretKey = process.env.TRUSTED_ACCOUNTS_SECRET_KEY;

try {
const response = await fetch('https://api.trustedaccounts.org/email/validate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${secretKey}`
},
body: JSON.stringify({
email: email,
options: {
validateSMTP: true,
validateMX: true,
checkDisposable: true,
checkTypo: true
}
})
});

const result = await response.json();

if (result.valid) {
res.json({
valid: true,
message: 'Email is valid',
details: result
});
} else {
res.status(400).json({
valid: false,
message: 'Email validation failed',
reason: result.reason,
suggestions: result.suggestions
});
}
} catch (error) {
console.error('Email validation error:', error);
res.status(500).json({ error: 'Validation service unavailable' });
}
});

Python/Django Example​

import requests
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import json
import os

@csrf_exempt
def validate_email(request):
if request.method == 'POST':
data = json.loads(request.body)
email = data.get('email')
secret_key = os.getenv('TRUSTED_ACCOUNTS_SECRET_KEY')

# Validate email
validate_url = 'https://api.trustedaccounts.org/email/validate'
validate_data = {
'email': email,
'options': {
'validateSMTP': True,
'validateMX': True,
'checkDisposable': True,
'checkTypo': True
}
}

headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {secret_key}'
}

try:
response = requests.post(validate_url, json=validate_data, headers=headers)
result = response.json()

if result.get('valid'):
return JsonResponse({
'valid': True,
'message': 'Email is valid',
'details': result
})
else:
return JsonResponse({
'valid': False,
'message': 'Email validation failed',
'reason': result.get('reason'),
'suggestions': result.get('suggestions')
}, status=400)

except requests.RequestException as e:
return JsonResponse({
'error': 'Validation service unavailable'
}, status=500)

return JsonResponse({'error': 'Invalid request'}, status=400)

PHP Example​

<?php
if ($_POST) {
$email = $_POST['email'];
$secret_key = getenv('TRUSTED_ACCOUNTS_SECRET_KEY');

// Validate email
$validate_url = 'https://api.trustedaccounts.org/email/validate';
$validate_data = json_encode([
'email' => $email,
'options' => [
'validateSMTP' => true,
'validateMX' => true,
'checkDisposable' => true,
'checkTypo' => true
]
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $validate_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $validate_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $secret_key
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code === 200) {
$result = json_decode($response, true);

if ($result['valid']) {
echo json_encode([
'valid' => true,
'message' => 'Email is valid',
'details' => $result
]);
} else {
http_response_code(400);
echo json_encode([
'valid' => false,
'message' => 'Email validation failed',
'reason' => $result['reason'],
'suggestions' => $result['suggestions']
]);
}
} else {
http_response_code(500);
echo json_encode(['error' => 'Validation service unavailable']);
}
}
?>

πŸ“Š Validation Results​

The API returns detailed validation results:

{
"valid": true,
"email": "user@example.com",
"domain": "example.com",
"mx": {
"valid": true,
"records": ["mx1.example.com", "mx2.example.com"]
},
"smtp": {
"valid": true,
"deliverable": true,
"catchAll": false
},
"disposable": false,
"role": false,
"free": false,
"typo": false,
"suggestions": [],
"confidence": 0.95
}

🎯 Use Cases​

  • Form Validation: Real-time email validation in registration forms
  • Lead Quality: Ensure marketing leads have valid email addresses
  • Data Cleaning: Clean existing email databases
  • Bounce Prevention: Reduce email bounce rates
  • Fraud Detection: Identify suspicious email patterns

πŸ“ˆ Best Practices​

  1. Real-time Validation: Validate emails as users type
  2. User Feedback: Provide clear error messages and suggestions
  3. Fallback Handling: Handle API failures gracefully
  4. Rate Limiting: Implement appropriate rate limiting
  5. Caching: Cache validation results for repeated emails

Ready to implement? Get your publishable key from the Developer Console and start validating emails!