Article
How to Build an Email Verification Service From Scratch: Practical Steps and Pitfalls
By Unlimited Verifier Team ·

Summary
Building an email verification service means running a pipeline of syntax checks, MX record lookups, and SMTP RCPT TO probes that never send mail. The core logic is short; the difficulty lies in ambiguous responses such as greylisting, catch-all domains, and rate limits that determine whether results can be trusted.Building an email verification service from scratch means writing a pipeline that checks syntax, looks up each domain's MX records, and runs an SMTP handshake on port 25 that asks the mail server about each recipient with RCPT TO but never sends a message. The core logic is short. The hard part is the ambiguous answers (greylisting, catch-all domains, rate limits and blocklists), which decide whether your results can be trusted.
Quick answer
- Pipeline: normalise the address, validate its syntax, resolve MX records, run an SMTP
RCPT TOprobe, test the domain for catch-all behaviour, then classify each address as Valid, Risky, Invalid or Unknown. - Infrastructure usually decides success. Outbound port 25, a clean IP and a matching reverse DNS (PTR) record matter as much as the code.
- Read a 250 as "accepted for now," not "delivered." Catch-all domains accept everything, so they need a separate test.
- Throttle per recipient domain. One large provider can set your total runtime, and bursts from one IP get blocked.
- Build only for a specific reason. At the assumptions in our worked example, buying is far cheaper for most teams.
What is an email verification service, and what does building one involve?
An email verification service takes a list of addresses and estimates whether each one can receive mail, without sending a message. It runs checks in order of cost: format, domain, mail server, and finally the mailbox itself.
Building one means owning every layer: the parser, the DNS resolver, the SMTP client, the retry and throttling logic, the reference lists, the storage, and the infrastructure that keeps your probes from being blocked. Each layer fails in its own way, and the failures look alike from the outside. A "Risky" or "Unknown" result can mean a catch-all server, a greylisted probe or a blocked IP, and your classifier has to tell these apart.
For the broader decision, see our guide to self-hosted email verification. This article focuses on the engineering.
Bottom line: A verifier is a pipeline of probes plus a classifier. Most of the effort goes into the answers that are not clean yes-or-no results.
Should you build an email verification service or buy one?
Build when you need control over where data lives, custom classification rules, or a volume that makes a per-run service unattractive. Buy when you need reliable results this week and do not want to run mail-facing infrastructure.
| Option | Time to first result | Main ongoing cost | Who carries IP reputation risk | How uncertain results are handled | Best fit |
|---|---|---|---|---|---|
| Build from scratch | Typically weeks to months to reach production quality | Engineering time for retries, blocklists and provider quirks | You, fully | Whatever you design, and whatever you measure | Teams with data-residency rules or unusual classification needs |
| Self-hosted open source | Hours to days, depending on infrastructure | Server, IP setup and keeping upstream code current | You, fully | Inherits the project's choices, which you must audit | Developers who want a tested engine without writing one |
| Hosted bulk verifier | Minutes (upload a CSV) | Subscription or per-run pricing | Vendor-managed | Vendor's own buckets; Unlimited Verifier sorts results into Valid, Risky and Invalid | Marketing, sales and operations teams who need answers quickly |
The open-source route has real trade-offs, which our review of the pros and cons of open-source email verifiers covers. Unlimited Verifier publishes its free email verifier source on GitHub, and the Rust project check-if-email-exists (the engine behind the Reacher tool) is another starting point; see our Reacher review. Both give you a working base, not a finished service. For cost modelling, self-hosted vs SaaS email verification cost sets out the variables.
If you are weighing purchases, best email verification tools compares hosted options on the criteria list owners care about. Whichever route you take, the price you compare against is the email verification pricing of the hosted option, not its headline rate.
Bottom line: Building gives you ownership, and it costs you ongoing operations. Decide based on which of those you actually need.
What are the layers of an email verification pipeline?
A complete pipeline runs five layers in order, from cheapest to most expensive. Stop early when a layer gives a definitive answer, because every SMTP probe costs time and reputation.
| Layer | What it checks | Typical failure | Mitigation |
|---|---|---|---|
| 1. Syntax | Local part and domain format, per RFC 5321 and RFC 5322 | An over-strict regex rejects legal addresses | Use a grammar-aware parser, not one regex |
| 2. DNS | MX records, falling back to the A record | Stale cache, timeouts, null MX | Cache by TTL; handle RFC 7505 null MX |
| 3. SMTP probe | Whether the mail server accepts RCPT TO |
Greylisting, blocking, closed port 25 | Retry 4xx, throttle per domain, use clean IPs |
| 4. Catch-all test | Whether the domain accepts any address | False Valid results | Probe a random nonexistent address on the same domain |
| 5. Reference lists | Disposable, role-based and blocklisted domains | Lists go stale | Refresh on a schedule and record the source |
Bottom line: Order the layers from cheap to expensive, and stop early when a result is definitive.
How do you validate email syntax without rejecting real addresses?
Validate syntax against the grammar in the RFC, not a simple pattern. A pattern like ^.+@.+$ lets junk through, while a strict regex rejects addresses that are legal but unusual. RFC 5321 sets the size limits: the local part is capped at 64 octets and the domain at 255.
Handle these cases explicitly:
- Trim whitespace and lowercase the domain. Local parts are technically case-sensitive, but most major providers treat them case-insensitively, so lowercasing both is the practical default.
- Convert internationalised domains to punycode before the DNS lookup, so
münchen.deresolves correctly. - Reject obvious placeholders such as
test@test.comorname@example.combefore spending a DNS lookup on them. - Keep syntax failures separate from DNS failures. A syntax error is a typo. An NXDOMAIN means the domain does not exist. The two call for different fixes, so log them separately.
Bottom line: Use a grammar-aware parser, normalise before lookup, and keep rejection reasons separate so you can debug them later.
How do you look up MX records correctly?
Query the domain's MX records, sort them by preference (lowest value first), and try each host in turn. If there are no MX records, RFC 5321 says to fall back to the domain's A record, which acts as an implicit MX.
Three details catch people out:
- Null MX. A domain that publishes a single MX record with preference 0 and host
.is declaring that it accepts no mail. RFC 7505 defines this. Classify these addresses as Invalid without probing. - Separate no-domain from no-mail. NXDOMAIN means the domain does not exist. A missing MX with an A record means you should probe the A record.
- Cache by the record's TTL. A large list often has thousands of addresses at the same domain. Cache the MX answer for the TTL it returns, so you query each domain once per cache window.
Bottom line: MX logic is simple to write but has three edge cases, so write them down and test each one.
How does the SMTP mailbox check work, and what do the response codes mean?
An SMTP mailbox check opens a connection to the MX host, announces itself with EHLO, declares a sender with MAIL FROM, asks about the recipient with RCPT TO, and then quits. It must never send DATA, because that would deliver a message.
Here is a minimal illustrative probe in Python using smtplib and dnspython. It is a teaching sketch with no retry logic, throttling or catch-all test.
import smtplib
import dns.resolver # pip install dnspython
def mx_hosts(domain):
try:
answers = dns.resolver.resolve(domain, "MX")
except dns.resolver.NXDOMAIN:
return [] # domain does not exist
except dns.resolver.NoAnswer:
return [domain] # RFC 5321 implicit MX: try the A record
except dns.exception.DNSException:
return [] # resolver timeout or failure
hosts = sorted((r.preference, str(r.exchange).rstrip(".")) for r in answers)
return [h for _, h in hosts]
def probe(address, sender="verify@check.yourdomain.example"):
domain = address.rsplit("@", 1)[1]
for host in mx_hosts(domain):
try:
with smtplib.SMTP(host, 25, timeout=10) as smtp:
smtp.ehlo("check.yourdomain.example")
smtp.mail(sender)
code, _ = smtp.rcpt(address)
return code # 250 accepted, 550 rejected, 4xx temporary
except (smtplib.SMTPException, OSError):
continue # timeout or refusal: try the next MX host
return None # no host reachable
The raw code is only the start, so classify it. Enhanced status codes from RFC 3463 add the detail you need:
| Response | Meaning | Suggested classification |
|---|---|---|
250 to RCPT TO |
Server will accept mail for this address now | Valid candidate; run the catch-all test |
| 550 5.1.1 | Mailbox does not exist | Invalid |
| 550 5.1.2 or 5.1.3 | Bad destination host or bad address syntax | Invalid |
| 552 5.2.2 | Mailbox full | Risky: the address exists but cannot receive mail now |
| 450 or 451 4.x.x | Temporary failure, often greylisting or rate limiting | Retry later |
| 421 | Service unavailable; server closing the channel | Back off and retry later |
| 550 5.7.1 or similar policy codes | Refused on policy or reputation grounds | Unknown, not Invalid |
| Timeout or connection refused | Port blocked or host unreachable | Unknown |
The 250 row matters most. It means the server did not reject the recipient at that moment. It does not prove the mailbox will accept a message later, and some servers return 250 for everything.
Bottom line: A 250 is a candidate result, not a verdict. Build the classifier around the codes, and treat policy refusals as Unknown rather than Invalid.
How do you detect catch-all domains?
To detect a catch-all, send RCPT TO for a random local part that almost certainly does not exist on the same domain, such as a 20-character random string. If the server accepts it, the domain accepts everything, and a 250 for your real address tells you nothing.
Run this test once per domain and cache the result, because the answer rarely changes day to day. Classify every address on a catch-all domain as Risky, not Valid. That single rule prevents the most common false positive in homemade verifiers.
Catch-all detection is one of the harder parts to get right. Our overview of open-source catch-all detection tools compares how different projects approach it. If you want a hosted option, Catch-all email verification describes how Unlimited Verifier detects catch-all domains.
Bottom line: Test each domain once with a random address, cache the answer, and never call a catch-all address Valid.
How do you handle greylisting, rate limits and blocks?
Treat temporary failures as a scheduling problem, not a verdict. Greylisting servers deliberately reject first contact with a 4xx code and accept a retry after a delay. A probe that gets a 450 should be queued again, not marked Invalid.
Published greylisting examples use different delay windows, roughly 5 to 15 minutes. Our recommendation is to retry 4xx responses after 15 minutes and back off exponentially from there.
Rate limits are where most DIY verifiers fail. Mail providers watch for connections that look like abuse, and a sudden burst from one IP can get that IP blocked. Design around this:
- Limit concurrency per recipient domain. Give each MX host its own token bucket. Our starting default is two concurrent connections per host with a 10-second timeout. These are practitioner defaults, not published provider limits, so raise them only after a full run shows no 421 or 4xx responses.
- Use a clean IP with matching reverse DNS. Your PTR record should match the hostname you announce in
EHLO. Missing or mismatched PTR records are a common cause of rejections. - Check outbound port 25 before building anything. Many residential ISPs and cloud providers restrict it. AWS, for example, restricts outbound port 25 on EC2 by default and requires a request to lift it. Test from your target host and read your provider's policy first.
- Decide on proxies deliberately. Rotating IPs can spread load, but they raise questions about how you identify yourself. Our guide covers whether proxies help with SMTP email verification.
If most of your results come back Unknown, the cause is usually infrastructure rather than the address list. Why self-hosted verification returns Unknown walks through the common causes.
Bottom line: Retry temporary failures, throttle per domain, and sort out your IP, reverse DNS and port 25 before you write more classification code.
How do you flag disposable, role-based and blocklisted addresses?
Disposable, role-based and blocklist checks are lookups against reference data, and they are cheap to run. They flag addresses that will accept mail but are poor prospects for sending.
- Disposable domains. Maintain a list of throwaway providers and refresh it at least monthly, because new services appear often.
- Role-based local parts. Prefixes such as
info@,sales@,admin@andsupport@usually belong to a team, which matters for consent and engagement. - Blocklists. Check the domain or sending IP against DNS blocklists. Spamhaus publishes widely used lists and documents how to query them.
Treat these flags as signals on top of the SMTP result, not replacements for it. A disposable address can be valid, and a role address can belong to a real person.
Bottom line: These checks are cheap and worth running on every address, but they describe risk rather than whether a mailbox exists.
How do you design the service architecture?
A production verifier separates intake, queuing, probing, classification and storage, so a slow mail server cannot block the rest of the system. A practical design has five components:
- Intake. Accept CSV or Excel uploads and an email verification API and automation endpoint. Normalise and deduplicate addresses here, before any network call.
- Queue. Key each address to its recipient domain. This is what makes per-domain throttling practical.
- Workers. Probe workers pull from the queue, respect each domain's token bucket, and push results back. Retry 4xx responses with exponential backoff.
- Classifier. Combine the SMTP code, catch-all result, disposable and role flags, and blocklist status into Valid, Risky, Invalid or Unknown.
- Storage and export. Store results with a defined retention window, and export as CSV, Excel or JSON.
If you need real-time checks at signup, the same classifier can sit behind an endpoint. Our guide to real-time email validation covers the trade-offs. Unlimited Verifier's email verification API accepts single-address checks and bulk batches of up to 10,000 emails per request, which is one way to avoid building intake yourself.
For hardware and capacity planning, see email verification server requirements.
Bottom line: Separate slow network work from fast decisions, and make per-domain throttling a first-class part of the queue.
Is it legal and acceptable to probe mail servers?
Probing is not prohibited by default, but three constraints apply. First, mail providers' acceptable-use terms can restrict high-volume probing, so read them before you scale. Second, results about people are personal data. Under the EU's GDPR, you need a lawful basis for processing them and a documented retention period. Third, probing addresses you have no relationship with can look like harvesting, which damages your IP reputation.
Get legal advice for your jurisdiction. For data handling choices, self-hosted email validation for data residency explains why some teams build for location control, and email verification compliance and hygiene covers the wider obligations.
Bottom line: Probing is workable when you scope it, document it and respect provider policies. Verification results are personal data, so manage them as such.
How do you measure whether your verifier is accurate?
Measure accuracy against a labelled set of addresses whose real outcomes you already know. Your own bounce logs are the best source, because they show which addresses delivered and which bounced.
Build a gold set of a few thousand addresses you have mailed, run your verifier on them, and compare. The key metric is the false-Valid rate: the share of addresses marked Valid that later bounced. Bounce logs only cover addresses you actually mailed, so measure this on mailed addresses and say so when you report it.
Illustrative example: your verifier marks 2,500 mailed addresses as Valid. Your later campaign shows 40 of them bounced. 40 ÷ 2,500 = 1.6% false-Valid rate
Track this number over time, alongside precision and recall. Unlimited Verifier states 99.5% accuracy for its deep verification. That is the company's own figure, not an independent benchmark, so measure your own build against your own data.
Bottom line: Judge your verifier by its false-Valid rate on real bounce data, not by how clean its code looks.
Hands-on tutorial: how do you run your first verification pass?
This tutorial takes you from zero to a first set of results in an afternoon. It is a learning exercise, so run it only on addresses you own or have consent to test.
- Test port 25 from your server. Run
nc -vz gmail-smtp-in.l.google.com 25. If the connection fails, fix your network or provider policy before going further. - Set your PTR record. Ask your host to set reverse DNS to the hostname you will announce in
EHLO, then confirm it with a reverse lookup. - Install dnspython. Run
pip install dnspython. - Create a test file. Put 20 addresses you control or have consent to test into
test_addresses.txt, one per line. Include at least two you know are invalid. - Run the probe. Save the sketch above as
probe.pyand add a loop at the bottom:
for addr in open("test_addresses.txt").read().split():
print(addr, probe(addr))
- Classify by hand. Map each code to Valid, Risky, Invalid or Unknown using the response table, and note where you are unsure.
- Compare with a hosted check. Upload the same file to Upload and verify a list. It accepts CSV and Excel files up to 10MB and detects the email column automatically. Unlimited Verifier sorts results into three buckets, Valid, Risky and Invalid, so decide in advance how your Unknown results map to them.
For quick spot-checks while you test, the Free email checker runs single-address checks in one step. To see how a full pipeline behaves on a larger sample, how to run check-if-email-exists with Docker is a useful next step.
Bottom line: Twenty addresses and one afternoon will teach you more about your pipeline than reading documentation, and a side-by-side comparison shows where your classifier disagrees.
Is building cheaper than buying at 500,000 addresses a month?
At the assumptions below, no. Buying costs a few dollars a month, and the engineering and hosting you would need to match it cost far more. The case for building rests on control, not savings. The engineering rate and hosting costs in this example are illustrative assumptions, so replace them with your own.
Scenario: You verify 500,000 addresses a month.
Buying. Pro costs $29 a month, or $25 a month billed annually. It allows unlimited lists of up to 25,000 emails each, and standard verification is unlimited on every plan.
500,000 ÷ 25,000 = 20 lists per month Monthly billing: 12 × $29 = $348 a year. Annual billing: 12 × $25 = $300 a year.
Two limits matter here. Pro includes 25,000 deep verifications a month, so if you need deep checks across the whole batch, the arithmetic changes. Pushing 500,000 addresses a month through the API would also use five months of the 100,000-email API allowance, so use CSV uploads for batches of this size.
Building (illustrative assumptions):
- First version: 80 engineering hours at $100 an hour = $8,000
- Ongoing upkeep: 4 hours a month for blocklists, provider quirks and retries = $400 a month
- Infrastructure: a server, a static IP and monitoring, assumed at $30 a month
- Monthly running cost: $400 + $30 = $430
- Year one: $8,000 + (12 × $430) = $13,160
- Year two onward: 12 × $430 = $5,160 a year
Even before upkeep, the $30 infrastructure assumption alone costs more than one month of Pro. The comparison only shifts if your team's time is free, if you need custom classification the vendor cannot offer, or if data location rules rule out hosted processing.
Runtime check. Suppose 40% of the 500,000 addresses (200,000) sit at one large provider that accepts two concurrent connections, and each probe takes 2 seconds.
200,000 ÷ 2 connections × 2 seconds = 200,000 seconds ≈ 55.6 hours
The other 300,000 addresses, spread across other domains with 50 concurrent workers, finish in about 3.3 hours. Because the work runs in parallel, the throttled provider sets your total runtime: about 56 hours, not 3.3. This is why per-domain throttling is the design decision that matters most, and why a hosted service that has already solved this is worth pricing in.
Bottom line: At these assumptions buying is far cheaper, and the single largest provider in your list decides how long a build takes to run.
What mistakes sink a homemade email verifier?
- Using one regex as the only syntax check. It either lets junk through or rejects legal addresses. Use a parser and test the edge cases.
- Probing from a home connection or an unconfigured server. Blocked port 25 and missing PTR records produce mass Unknown results.
- Treating a 250 as proof of delivery. Catch-all domains make this the most common source of false Valid results.
- Marking 4xx responses as Invalid. Greylisting and rate limits are temporary, so retry them.
- Skipping per-domain throttling. One burst can get your IP blocked and distort every later result.
- Sending
DATAduring tests. A probe should stop atRCPT TO. Anything beyond that delivers mail. - Letting reference lists go stale. Disposable and blocklist data changes quickly, so schedule refreshes.
- Storing results with no retention policy. Verification output is personal data, so document how long you keep it.
- Never measuring accuracy. Without a labelled gold set and a false-Valid rate, you cannot tell whether the classifier works.
- Forcing every result into Valid or Invalid. Unknown is a legitimate answer. Hiding it inflates your Valid count and your bounce rate.
Bottom line: Homemade verifiers usually fail on infrastructure and classification, not on the parts that look hard in code.
How we compared (and limitations)
This guide is based on public documentation: the RFCs for SMTP, enhanced status codes and null MX records; the GDPR text; and Spamhaus's published guidance on its lists. We have not run controlled tests against any mail provider's servers. Provider behaviour changes without notice, so treat the response mappings as a starting point to validate against your own data.
Unlimited Verifier's figures come from its own published plan details. The 99.5% accuracy figure is the company's stated figure for deep verification. The cost and runtime examples are illustrative, and the engineering rate and hosting costs are assumptions to replace with your own.
When you are ready to compare a build against a working system, sign up for a free Unlimited Verifier account and run the same test file. For ongoing hygiene once your list is clean, see email list maintenance best practices, and for outbound teams, email verification for sales prospecting shows how verified results feed a campaign.
Classification framework
| Signal | Result | Classification |
|---|---|---|
| Syntax fails | Reject before DNS | Invalid |
| No MX record | Domain cannot receive mail | Invalid |
| 250 and domain is not catch-all | Mailbox accepted | Valid |
| 250 and domain is catch-all | Accepted for any address | Risky |
| 4xx deferral, persistent | Probe inconclusive | Unknown |
| 550 or 5.1.1 | Mailbox does not exist | Invalid |
Frequently asked questions
Is it legal to verify email addresses with an SMTP check?
Generally yes, when done responsibly, because the probe stops before any message is sent. Check your jurisdiction's rules and your providers' acceptable-use policies, and avoid harvesting addresses without a lawful basis.
Why do I need port 25 open?
SMTP servers receive mail on port 25, so an SMTP probe must connect there. Many cloud providers block outbound port 25 by default and require a support request to unblock it.
What is a catch-all domain?
A catch-all domain accepts mail for any local part, so a 250 response proves nothing about a specific mailbox. You need a separate test, such as probing a random made-up address on the same domain, to detect it.
What does greylisting do to verification results?
Greylisting makes servers temporarily reject first-time senders with a 4xx code. Retry later from the same IP, and classify persistent deferrals as Unknown rather than Invalid.
Why do I need a PTR record?
Many mail servers reject connections from IPs without matching reverse DNS. A PTR record that resolves back to your HELO hostname improves acceptance and reduces blocks.
How fast can I run SMTP probes?
Throttle per recipient domain rather than globally. Large providers rate-limit and blocklist bursts, so spreading probes across time and IPs keeps results usable.
Does a 250 response guarantee delivery?
No. A 250 at RCPT TO means the server accepted the address at that moment, not that the mailbox is active or that mail will be delivered.
When is buying a verifier cheaper than building one?
Buying usually wins for low to moderate volumes or when you need results quickly, because building requires IP management, blocklist handling, and ongoing engineering maintenance.
Cut Bounces and Protect Your Sender Reputation With Unlimited Email Verification
Every invalid address you send to hurts your sender reputation and your inbox placement. Verifying your list before each send means fewer bounces, healthier deliverability, and a predictable cost. With Unlimited Verifier, standard verification is unlimited on every plan, with no per-email fees.
Unlimited Verifier checks syntax, domain, MX records and the SMTP mailbox. It also detects catch-all domains and flags disposable and role-based addresses. Export a CSV from your email platform or CRM, upload and verify the list, then re-import the clean results. You can also automate checks with the email verification API.
| Free | Pro | |
|---|---|---|
| Price | $0 | $29/month ($25/month billed annually) |
| Lists | 25 a month, up to 150 emails each | Unlimited, up to 25,000 emails each |
| Deep verifications | 750 a month | 25,000 a month |
| API access | No | Yes (100,000 emails a month) |
| Result retention | 24 hours | 30 days |
Why teams choose Unlimited Verifier
- Unlimited standard verification on all plans, including Free, with no per-email fees.
- Catch-all detection so you know which domains accept every address.
- Clear Valid / Risky / Invalid results, exportable as CSV, Excel or JSON.
- An open-source verification engine you can inspect on GitHub.
Unlimited Verifier states 99.5% accuracy for deep verification.
Create a free account and verify your next list before you hit send.
Want to test a single address first? Try the free email checker.