← Code samples
Email
Email Validation
Validate an email address at signup or form submission — flag disposable, role, and public-domain addresses, and apply your own block rules, before it enters your product.
Validate an email before creating an account, saving a lead, or sending a campaign. The API returns flags for disposable addresses, role accounts, public domains, and typo suggestions — and applies any custom rules you've configured. Each check costs 1 credit.
Endpoint
HTTP
POST https://app.verifence.io/api/scan/email
API-KEY: your_api_key
Content-Type: application/json Request body
| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | The email address to validate |
ip | string | No | Submitter's IP — enables IP and country rule checks |
Response fields
| Field | Type | Description |
|---|---|---|
ok | boolean | true if the request succeeded |
email | string | The submitted address |
domain | string | The domain part of the address |
disposable | boolean | true if from a disposable or temporary provider |
email_blocked | boolean | true if the address or domain matched one of your block rules |
role_account | boolean | true if a role address (admin, info, noreply, etc.) |
public_domain | boolean | true if a consumer provider (Gmail, Yahoo, etc.) |
did_you_mean | string | null | Typo-corrected suggestion, or null |
ip_blocked | boolean | null | true if the IP matched a block rule (only when ip is passed) |
country_blocked | boolean | null | true if the country matched a block rule (only when ip is passed) |
cURL
cURL
curl -X POST https://app.verifence.io/api/scan/email \
-H "API-KEY: your_api_key" \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "ip": "203.0.113.42"}' JSON — response
{
"ok": true,
"email": "user@example.com",
"domain": "example.com",
"disposable": false,
"email_blocked": false,
"role_account": false,
"public_domain": false,
"did_you_mean": null,
"ip_blocked": false,
"country_blocked": false
} PHP
PHP
function validateEmail(string $email, string $ip = null): array
{
$payload = ['email' => $email];
if ($ip) {
$payload['ip'] = $ip;
}
$ch = curl_init('https://app.verifence.io/api/scan/email');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'API-KEY: ' . getenv('VERIFENCE_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_TIMEOUT => 5,
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true) ?? [];
}
// Usage — e.g. in a registration controller
$result = validateEmail($request->email, $request->ip());
if (!($result['ok'] ?? false)) {
return back()->withErrors(['email' => 'Unable to validate email. Please try again.']);
}
if ($result['disposable']) {
return back()->withErrors(['email' => 'Disposable email addresses are not allowed.']);
}
if ($result['role_account']) {
return back()->withErrors(['email' => 'Please use a personal email address.']);
} Node.js
Node.js
async function validateEmail(email, ip = null) {
const payload = { email };
if (ip) payload.ip = ip;
const res = await fetch('https://app.verifence.io/api/scan/email', {
method: 'POST',
headers: {
'API-KEY': process.env.VERIFENCE_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
signal: AbortSignal.timeout(5000),
});
if (!res.ok) {
throw new Error(`Verifence API error: ${res.status}`);
}
return res.json();
}
// Usage — e.g. in an Express registration route
app.post('/register', async (req, res) => {
const result = await validateEmail(req.body.email, req.ip);
if (!result.ok) {
return res.status(422).json({ error: 'Unable to validate email.' });
}
if (result.disposable) {
return res.status(422).json({ error: 'Disposable email addresses are not allowed.' });
}
if (result.role_account) {
return res.status(422).json({ error: 'Please use a personal email address.' });
}
const user = await createUser({ email: req.body.email });
res.json({ user });
}); Python
Python
import os
import requests
def validate_email(email: str, ip: str = None) -> dict:
payload = {"email": email}
if ip:
payload["ip"] = ip
response = requests.post(
"https://app.verifence.io/api/scan/email",
json=payload,
headers={"API-KEY": os.environ["VERIFENCE_API_KEY"]},
timeout=5,
)
response.raise_for_status()
return response.json()
# Usage — e.g. in a Flask or Django registration view
result = validate_email(email, ip)
if not result.get("ok"):
return error_response("Unable to validate email.")
if result.get("disposable"):
return error_response("Disposable email addresses are not allowed.")
if result.get("role_account"):
return error_response("Please use a personal email address.")
suggestion = result.get("did_you_mean")
if suggestion:
# Optionally surface "Did you mean {suggestion}?" to the user
pass Handling the response
A minimal decision tree for most use cases:
Logic
disposable = true -> reject, explain why
email_blocked = true -> reject (matched your rules)
role_account = true -> reject or warn (depends on your use case)
ip_blocked = true -> reject silently or show a generic error
country_blocked = true -> reject with an appropriate message
did_you_mean != null -> show a suggestion: "Did you mean X?"
all clear -> accept For B2B products you may also reject public_domain = true addresses. For consumer products that would block most legitimate users — use your judgement.