Integrate real-time email verification into your Python application in minutes
using the requests library.
pip install requests
Send a GET request with the email and your API token, and check the HTTP status before reading the result.
The helper below returns one of three decisions: accept, reject or defer.
Running out of credits (402), a rate limit (429), an outage or an Unknown result
never becomes a rejection, and a temporary Unknown is asked again after RetryAfterSeconds.
import time
import requests
API_URL = "https://api.validemail.net/"
API_KEY = "YOUR_API_KEY" # find it in your ValidEmail dashboard; keep it on your server
def verify_email(email: str, max_attempts: int = 3) -> tuple[str, str]:
"""Return (decision, reason). decision is "accept", "reject" or "defer".
"defer" means: let the user continue, keep the address flagged, check it again later.
Running out of credits, a rate limit or an outage never turns into "reject".
"""
for _ in range(max_attempts):
try:
response = requests.get(API_URL, params={"email": email, "token": API_KEY}, timeout=90)
except requests.RequestException as error:
return "defer", f"network: {error}"
# 1. The HTTP status first: only a 200 carries a verdict about the address.
if response.status_code == 402:
print("ValidEmail is out of credits.", response.text) # alert whoever pays the bill
return "defer", "no_credits"
if response.status_code == 429:
time.sleep(int(response.headers.get("Retry-After", "1")))
continue
if response.status_code != 200:
return "defer", f"http_{response.status_code}"
# 2. Then the verdict.
result = response.json()
if result["State"] == "Deliverable":
return "accept", result["Reason"]
if result["State"] == "Not Deliverable":
return "reject", result["Reason"]
if result.get("RetryAfterSeconds"):
# Still being resolved (greylisting, a slow server). Asking again for the same address is free.
time.sleep(result["RetryAfterSeconds"])
continue
return "defer", result["Reason"] # Unknown, and no answer is coming
return "defer", "still pending"
decision, reason = verify_email("someone@example.com")
print(f"{decision}: {reason}")
State = "Unknown")
Some mail servers greylist first-time senders or respond slowly. Instead of failing, the API returns an
interim 200 OK result with State = "Unknown", a Reason of
PENDING or GREYLISTED, and a RetryAfterSeconds hint while the
verification finishes in the background.
RetryAfterSeconds seconds, then repeat the same request to get the final verdict.Unknown as "not yet decided" — never as a delivery failure.The balance endpoint is free to call and never consumes a credit — perfect for a pre-flight check before verifying a large list.
balance = requests.get(
"https://api.validemail.net/balance",
params={"token": API_KEY},
timeout=30,
).json()["balance"]
print(f"Credits remaining: {balance}")
| HTTP Status | Meaning | What to do |
|---|---|---|
| 200 OK | The request was processed. Check State — a result with State = "Unknown" and a RetryAfterSeconds value is an interim answer, not a final verdict. |
Use the result. If State is Unknown, retry the same request after RetryAfterSeconds. |
| 400 Bad Request | Missing email/token parameter, or a transient processing failure. |
Check the response text and retry. |
| 402 Payment Required | No credits remaining. The JSON body says what is missing and what fixes it: {"error":"no_credits","shortfall":1,"pack":{"credits":5000,"price":9.50,"currency":"USD"},"buyUrl":"https://validemail.net/BuyCredits?credits=5000","message":"…"}. |
Stop sending requests, open buyUrl to top up (the pack is preselected), then retry. Need an invoice or a larger volume? Email info@validemail.net. |
| 401 Unauthorized | The API key is invalid or unknown. | Verify the token value against the API key shown in your dashboard. |
| 403 Forbidden | The account attached to this API key is inactive. | Contact info@validemail.net to reactivate the account. |
| 429 Too Many Requests | You exceeded your per-second request limit. The response body includes the configured limit. | Slow down and retry with backoff, or contact us to raise your rate limit. |
Explore every response field and status code in the full API reference.
Hi. I'm ValidEmail's AI assistant. Ask me about verifying a list, the API, prices or your account.