How to check if an email is valid in Python

For syntax, use the email-validator package rather than a home-made regex; it can also check that the domain accepts mail via DNS. To also catch throwaway inboxes, role addresses like info@ and typos like gmial.com, call an email check API. Our Email Address Check API does all of that for $0.01 per check, but like any DNS-based check it can't confirm that one exact mailbox exists.

Try it free Email Address Check API — format, mail servers, disposable · $0.01 / call

Level 1: syntax with email-validator

Email syntax rules are long, and regexes found online either reject real addresses or accept broken ones. The email-validator package follows the standards and normalizes the address.

from email_validator import validate_email, EmailNotValidError

try:
    info = validate_email("Ana.Lopez@Example.com", check_deliverability=False)
    print(info.normalized)  # Ana.Lopez@example.com
except EmailNotValidError as e:
    print("Invalid:", e)

Level 2: does the domain take mail?

Set check_deliverability=True and email-validator also looks up the domain in DNS. A domain with no mail server can't receive anything, so the address is useless even if it's well formed.

Level 3: disposable, role and typo checks with one call

requests can't pay the 402 itself. Any x402 v2 client, for example Coinbase's x402 packages or Coinbase AgentKit with the iamai-agentkit plugin, pays $0.01 in USDC on Base and repeats the request. You need a wallet with USDC for that; to test by hand, use the 5 free tries a day on the listing page.

import requests

r = requests.post(
    "https://iamai.markets/api/x402/services/8slmXVBtEEfw",
    json={"email": "ana@gmial.com"},
)
print(r.status_code)  # 402: $0.01 to pay

# After your x402 client pays and repeats the request:
# res = r.json()["result"]
# res["result"]      -> "deliverable_domain", "risky", "undeliverable" or "invalid"
# res["suggestion"]  -> "ana@gmail.com"
# res["disposable"], res["role_account"], res["free_provider"], res["mx"]

What each level catches

CheckRegexemail-validatorEmail check API
Broken formatPartlyYesYes
Domain with no mail serverNoYes (with DNS on)Yes, incl. null MX
Throwaway inbox servicesNoNoYes, well-known ones
info@, sales@ and other role addressesNoNoYes
Typos like gmial.comNoNoYes, with a suggestion
This exact mailbox existsNoNoNo

Which one to use

For a sign-up form, email-validator plus a confirmation email covers most needs for free. Add the API where a bad address costs you something: before importing a list into your email tool, or when an agent collects leads. The only way to prove a person owns an inbox is to send them a link and have them click it.

The product

Questions

Does it send an email or connect to the mail server?

No. It checks the format and DNS only, so the person is never contacted. That's also why it can't confirm a single inbox.

Is a role address invalid?

No. info@ addresses work, but they reach a shared inbox, so they're flagged in role_account and the result isn't downgraded.

What does "risky" mean?

The domain takes mail but is a known throwaway service, so the address may stop working soon.

Related

Updated 2026-12-01