Email verification runs three checks, one after the other. Each one asks a different question:
- Syntax: is this string shaped like an email address?
- MX lookup: can this domain receive email at all?
- SMTP check: does this specific mailbox exist?
Each check catches bad addresses the one before it can't see. jane@nonexistent-domain-xyz.com passes a syntax check. deleted.employee@real-company.com passes syntax and MX. Only the SMTP check reaches the mail server and asks about the mailbox itself.
This guide explains how each check works, what each one misses, and where all three run into limits. It includes Python code for the first two.
The short answer
| Check | What it asks | Network needed | Catches | Misses |
|---|---|---|---|---|
| Syntax | Is the format valid? | None | Typos, missing @, bad characters, over-long addresses |
Domains and mailboxes that don't exist |
| MX lookup | Does the domain accept mail? | DNS query | Made-up domains, expired domains, domains that accept no mail | Dead mailboxes on real domains |
| SMTP | Does the mailbox exist? | Connection to the mail server on port 25 | Deleted and never-existing mailboxes | Catch-all domains, servers that block verification |
Run them in that order and stop at the first failure. There's no point looking up DNS for jane..doe@ or opening an SMTP connection to a domain with no mail server.
Check 1: Syntax validation
A syntax check runs entirely on your machine. It makes no network calls, so it's instant and free, and it's the only check that belongs in a browser form.
The rules come from two standards
Two RFCs govern email addresses, and they don't say quite the same thing:
- RFC 5322 defines how addresses appear in message headers (From, To, Cc). Its grammar is very permissive. It allows quoted local parts like
"john smith"@example.comand comments in parentheses. - RFC 5321 defines SMTP, the protocol that actually moves mail. It sets the length limits: 64 characters for the local part (before the
@) and a 256-character path, which leaves 254 characters for a full address.
In practice, accept what real mailbox providers accept rather than everything RFC 5322 allows. Quoted local parts and comments are technically valid, but almost no real inboxes use them, and many mail systems reject them anyway.
What a practical syntax check tests
- Exactly one
@, with something on both sides - Local part of 1–64 characters, using letters, digits and
! # $ % & ' * + / = ? ^ _ { | } ~ - - No dot at the start or end of the local part, and no two dots in a row
- At least one dot in the domain
- Each domain label 1–63 characters, starting and ending with a letter or digit
- Full address of 254 characters or fewer
Plus addressing (jane+newsletter@example.com) is valid and widely used. Don't reject it. For the full rule set with valid and invalid examples, see our guide to email address format.
Internationalised addresses
Domains can contain non-Latin characters, like münchen.de. DNS can't store those directly, so they are converted to an ASCII form called Punycode: münchen.de becomes xn--mnchen-3ya.de. Convert to Punycode before you check domain labels or look up DNS. Otherwise you'll reject real addresses.
The local part can be non-ASCII too (用户@例子.广告), under RFC 6531. It only works when both the sending and the receiving server support the SMTPUTF8 extension. If your sending setup doesn't, flag these addresses rather than silently accepting them.
Why one regex isn't enough
Most developers start with a regular expression. The full RFC 5322 grammar can't be expressed as a regular expression in practice, because quoted strings and comments need a real parser. Short patterns go wrong in the other direction: some reject valid addresses, others accept broken ones. When we tested six popular patterns in our email validation regex comparison, none of them handled every test case.
Splitting the address and checking each part separately is easier to read and easier to get right:
import re
# Characters allowed in an unquoted local part (RFC 5322 "atext")
ATEXT = r"[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]"
LOCAL_RE = re.compile(rf"^{ATEXT}+(\.{ATEXT}+)*$")
LABEL_RE = re.compile(r"^[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?$")
def check_syntax(email: str) -> tuple[bool, str]:
"""Return (ok, reason). Pure string checks: no network calls."""
if len(email) > 254:
return False, "address is longer than 254 characters"
local, sep, domain = email.rpartition("@")
if not sep or not local or not domain:
return False, "needs exactly one local part, '@' and domain"
if len(local) > 64:
return False, "local part is longer than 64 characters"
if not LOCAL_RE.match(local):
return False, "local part has an invalid character or dot placement"
try:
# Converts internationalised domains (münchen.de) to their DNS form.
# Python's built-in codec follows IDNA 2003; for strict IDNA 2008
# rules, use the "idna" package instead.
ascii_domain = domain.encode("idna").decode("ascii")
except UnicodeError:
return False, "domain is not a valid internationalised name"
labels = ascii_domain.split(".")
if len(labels) < 2:
return False, "domain needs at least one dot"
for label in labels:
if not LABEL_RE.match(label):
return False, f"domain label '{label}' is invalid"
return True, "syntax ok"
if __name__ == "__main__":
for address in [
"jane.doe@example.com", # ok
"jane+news@example.com", # ok: plus addressing
"jane@münchen.de", # ok: internationalised domain
"jane..doe@example.com", # consecutive dots
".jane@example.com", # leading dot
"jane@example", # no dot in domain
"jane@-example.com", # label starts with a hyphen
"jane@@example.com", # two @ signs
"a" * 65 + "@example.com", # local part too long
]:
print(f"{address[:30]:32} {check_syntax(address)}")
Output:
jane.doe@example.com (True, 'syntax ok')
jane+news@example.com (True, 'syntax ok')
jane@münchen.de (True, 'syntax ok')
jane..doe@example.com (False, 'local part has an invalid character or dot placement')
.jane@example.com (False, 'local part has an invalid character or dot placement')
jane@example (False, 'domain needs at least one dot')
jane@-example.com (False, "domain label '-example' is invalid")
jane@@example.com (False, 'local part has an invalid character or dot placement')
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (False, 'local part is longer than 64 characters')
What syntax can't catch: anything that is well-formed but doesn't exist. ceo@made-up-domain-12345.org and a long-deleted Gmail address both pass. Syntax is a filter for typos, not proof that an address works.
Check 2: MX record lookup
The MX lookup is the first check that touches the network. It asks DNS one question: which servers accept mail for this domain?
How MX records work
A domain that receives email publishes one or more MX (mail exchanger) records. Each one names a mail server and a preference number. Lower numbers are tried first. Here are Gmail's:
gmail.com. MX 5 gmail-smtp-in.l.google.com.
gmail.com. MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com. MX 20 alt2.gmail-smtp-in.l.google.com.
gmail.com. MX 30 alt3.gmail-smtp-in.l.google.com.
gmail.com. MX 40 alt4.gmail-smtp-in.l.google.com.
A sending server tries gmail-smtp-in.l.google.com first and falls back down the list if it doesn't answer.
Three cases a basic check gets wrong
- No MX record at all. That doesn't automatically mean "can't receive mail". RFC 5321 says that if a domain has no MX record, senders should try its A or AAAA record (the domain's own IP address) instead. Few domains rely on this, but marking them invalid is wrong.
- A "null MX". RFC 7505 lets a domain state that it accepts no email by publishing a single MX record of
0 ..example.comdoes exactly this. A check that only asks "is there an MX record?" will wrongly pass it. - DNS timeouts. A failed lookup isn't proof the domain is dead. Treat it as unknown and retry.
This function handles all three. It uses the dnspython package:
# pip install dnspython
import dns.exception
import dns.resolver
def check_mx(domain: str) -> tuple[bool, str]:
"""Return (ok, reason) for whether the domain can receive mail."""
try:
answers = dns.resolver.resolve(domain, "MX", lifetime=5)
except dns.resolver.NXDOMAIN:
return False, "domain does not exist"
except dns.resolver.NoAnswer:
# No MX record: RFC 5321 says senders fall back to the A/AAAA record
for rtype in ("A", "AAAA"):
try:
dns.resolver.resolve(domain, rtype, lifetime=5)
return True, f"no MX record, falls back to {rtype} record"
except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN):
continue
return False, "no MX, A or AAAA record"
except (dns.resolver.NoNameservers, dns.exception.Timeout):
return False, "DNS lookup failed: treat as unknown and retry later"
records = sorted((r.preference, str(r.exchange)) for r in answers)
# A "null MX" (RFC 7505) is a single record of "0 ." and means
# "this domain accepts no email"
if records == [(0, ".")]:
return False, "domain publishes a null MX: it accepts no email"
return True, f"primary mail server: {records[0][1]}"
if __name__ == "__main__":
for domain in ["gmail.com", "example.com", "no-such-domain-mv-test.com"]:
print(f"{domain:30} {check_mx(domain)}")
gmail.com passes. example.com fails because of its null MX. The made-up domain fails because it doesn't exist.
What MX can't catch: dead mailboxes on real domains. gmail.com has healthy MX records whether or not absolutely-not-a-real-user@gmail.com exists. MX also doesn't stop disposable addresses, because temporary-inbox services run working mail servers. In our study of 9,963 disposable email domains, 78% passed a DNS mail check. You need a disposable-domain list for those.
Check 3: SMTP mailbox verification
The SMTP check is the only one that asks about the mailbox itself. It connects to the domain's mail server and starts sending an email, but hangs up before any message is sent.
The SMTP conversation, step by step
The verifier connects to the highest-priority MX host on port 25 and has this exchange (S: is the server, C: is the verifier):
S: 220 mx.example-company.com ESMTP ready
C: EHLO verifier.your-domain.com
S: 250 mx.example-company.com Hello
C: MAIL FROM:<check@your-domain.com>
S: 250 OK
C: RCPT TO:<jane@example-company.com>
S: 250 OK <- the mailbox exists
C: QUIT
S: 221 Bye
- Connect: the server greets the verifier with a
220code. - EHLO: the verifier introduces itself by hostname.
- MAIL FROM: the verifier gives a sender address.
- RCPT TO: the verifier names the address being checked. The server's reply to this command is the result.
- QUIT: the verifier hangs up. No
DATAcommand is sent, so no email is delivered.
SMTP response codes that matter
Codes starting with 2 mean success, 4 means a temporary failure (try again later), and 5 means a permanent failure.
| Code | Meaning | What to do |
|---|---|---|
| 250 | Mailbox accepted | Valid, unless the domain is a catch-all (see below) |
| 450 / 451 | Temporary failure, often greylisting | Retry later. Don't mark invalid |
| 452 | Mailbox full or too many recipients | The mailbox exists. Retry later |
| 550 | Mailbox unavailable, usually "user unknown" | Invalid: this would hard-bounce |
| 551 | User not local | Treat as invalid for that address |
| 552 | Storage limit exceeded | The mailbox exists but can't accept mail now |
| 553 | Mailbox name not allowed | Invalid |
| 421 | Service not available | The server is busy or rate-limiting you. Retry later |
Why SMTP checks are harder than they look
Mail servers know that spammers use the same conversation to harvest addresses, so many of them push back:
- Catch-all domains reply
250 OKto every address, real or not, so a250proves nothing. To detect them, also ask about a random address that can't exist. If the server accepts that too, the domain is a catch-all. Our guide to catch-all detection covers how to score these addresses. - Greylisting rejects the first attempt from an unknown sender with a
450or451, on the bet that a real mail server will retry and a spammer won't. A checker that doesn't retry will wrongly mark real addresses as bad. - Large providers block verification. Microsoft and Apple mail servers often refuse these checks outright. That result is unknown, not invalid.
- Port 25 is blocked on most cloud hosts and home connections, so SMTP checks can't run from an ordinary app server. They need servers with clean IP addresses and correct reverse DNS. A server with a poor reputation gets blocked, which makes every result unreliable.
This is why the SMTP check is the one teams usually hand to a verification service rather than run themselves.
How the three checks work together
Run them as a cascade, and stop as soon as one gives a definite answer:
- Syntax fails: invalid. No network call made.
- Domain doesn't exist, or has no mail server: invalid. One DNS query.
- SMTP says 550: invalid.
- SMTP says 250 and the domain is not a catch-all: valid.
- The domain is a catch-all: risky. You can't confirm the mailbox.
- Greylisting, a blocked provider or a timeout: unknown. Retry later.
Which checks to run depends on the moment:
- In a signup form: run syntax in the browser for instant feedback, then the full check on your server. Our signup form tutorial shows the front-end and back-end code.
- Before a campaign: run all three on the whole list in bulk. See real-time vs batch verification for when to use each.
Running all three checks with one API call
MailValid runs syntax, DNS, MX and SMTP checks, plus disposable, role-based and catch-all detection, in a single request:
curl -X POST https://mailvalid.io/api/v1/verify/single \
-H "X-API-Key: mv_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{"email": "john@company.com"}'
The response shows the outcome of each check separately:
{
"success": true,
"credits_used": 1,
"result": {
"email": "john@company.com",
"status": "valid",
"is_valid": true,
"syntax_valid": true,
"domain": "company.com",
"domain_valid": true,
"has_mx": true,
"mx_records": [{"priority": 10, "host": "mx1.company.com"}],
"smtp_checked": true,
"smtp_response_code": 250,
"is_disposable": false,
"is_role_based": false,
"is_catch_all": false,
"is_free_provider": false,
"confidence_score": 95,
"status_reason": "mailbox_confirmed",
"provider": "corporate",
"verification_time_ms": 234,
"cached": false
}
}
The status_reason field tells you which check produced the result:
| Check | status |
status_reason |
|---|---|---|
| Syntax | invalid |
failed_syntax_check |
| DNS / MX | invalid |
no_dns_entries, no_mx_records |
| SMTP | invalid |
mailbox_not_found (a 550 reply) |
| SMTP | valid |
mailbox_confirmed (a 250 reply) |
| SMTP | catch_all |
accept_all |
| SMTP | unknown |
greylisted, failed_smtp_connection, antispam_system |
| Other checks | do_not_mail |
disposable, role_based |
unknown results don't use a credit. The average response time is under 500ms. To check a list rather than one address, the bulk endpoint takes up to 10,000 emails per job. All status values are listed in the docs.
FAQ
Is a syntax check enough for a signup form? No. It stops typos, but it will accept any well-formed address on a domain that doesn't exist. Run it in the browser for instant feedback, then do the MX and SMTP checks on your server.
Can an SMTP check send an email by accident?
No. The verifier disconnects after RCPT TO, before the DATA command that carries the message. Nothing reaches the inbox.
Why do some Outlook or iCloud addresses come back as unknown? Microsoft and Apple mail servers often refuse verification attempts. The address may be perfectly fine, but the server won't say. Treat it as unknown, not invalid.
What does "catch-all" mean for my list? The domain accepts mail for any address, so you can't confirm the individual mailbox. Send to these addresses carefully: in smaller batches, after your confirmed-valid contacts.
Does verification guarantee delivery? No. It confirms the mailbox exists right now. Inbox placement also depends on your sender reputation and authentication. Our SPF, DKIM and DMARC guide covers that side.
Try all three checks on your own list: start free with 100 credits. No credit card needed, and credits never expire.