Temp mail
in Python.
Disposable inboxes for Python, in three lines of requests.
import os
import requests
API = "https://evilmail.pro"
headers = {"X-API-Key": os.environ["EVILMAIL_KEY"]}
# Create a disposable inbox that lives for 30 minutes
resp = requests.post(
f"{API}/api/temp-email",
headers={**headers, "Content-Type": "application/json"},
json={"ttlMinutes": 30},
timeout=15,
)
resp.raise_for_status()
data = resp.json()["data"]
print("Inbox:", data["email"])
print("Token:", data["sessionToken"])Spin up temp mail in Python whenever your tests, CI jobs, or scripts need a throwaway inbox — no SMTP server, no manual clicking. EvilMail gives you a simple HTTP API you can call with the requests library to create a disposable address, poll it for incoming mail, and pull out a signup link or a 6-digit OTP. It's built for developers automating email verification testing: register a fake user, wait for the confirmation email, extract the code, and assert on it, all inside one Python function that runs the same locally and in your pipeline.
Why use temp mail in Python
End-to-end signup tests
Register a new account against a real temp mailbox, wait for the welcome or confirmation email, and assert the flow works. No shared team inbox, no flaky manual steps.
OTP & 2FA automation
Trigger a login or password reset, poll the inbox, and regex the 6-digit code straight out of the message body so your test suite can complete the challenge unattended.
CI pipelines
Read the API key from an environment variable and run the exact same email checks in GitHub Actions, GitLab CI, or Jenkins that you run on your laptop.
Scraping & throwaway registrations
Generate a fresh disposable address per run to sign up for services you only need once, keeping your real inbox clean and rate-limit-free.
The flow — Python temp mail in 3 calls
Create a disposable inbox
import os
import requests
API = "https://evilmail.pro"
KEY = os.environ["EVILMAIL_KEY"]
def create_inbox(ttl_minutes=30):
"""Return (email, session_token) for a fresh inbox."""
resp = requests.post(
f"{API}/api/temp-email",
headers={
"X-API-Key": KEY,
"Content-Type": "application/json",
},
json={"ttlMinutes": ttl_minutes},
timeout=15,
)
resp.raise_for_status()
data = resp.json()["data"]
return data["email"], data["sessionToken"]
email, token = create_inbox()
print("Send mail to:", email)Poll until the email arrives
import time
import requests
def wait_for_message(token, attempts=20, delay=3):
"""Poll the inbox until at least one message shows up."""
for _ in range(attempts):
resp = requests.get(
f"{API}/api/temp-email/{token}",
headers={"X-API-Key": KEY},
timeout=15,
)
resp.raise_for_status()
messages = resp.json()["data"]["messages"]
if messages:
return messages[0] # newest message
time.sleep(delay)
raise TimeoutError("No email arrived in time")
msg = wait_for_message(token)
print("Got:", msg["subject"], "from", msg["from"])Read the message & extract the code
import re
import requests
def read_message(uid, token):
resp = requests.get(
f"{API}/api/message/{uid}",
headers={"X-API-Key": KEY},
params={"token": token},
timeout=15,
)
resp.raise_for_status()
return resp.json()["data"]
def extract_otp(text):
match = re.search(r"\b(\d{6})\b", text or "")
return match.group(1) if match else None
body = read_message(msg["uid"], token)
otp = extract_otp(body["text"])
print("OTP:", otp)Python temp mail — FAQ
Q1How do I get a temp mail address in Python?−
Send a POST request to https://evilmail.pro/api/temp-email with your X-API-Key header and a JSON body like {"ttlMinutes": 30}. The response contains data.email (the disposable address) and data.sessionToken, which you use for every follow-up call. The hero snippet above does exactly this in about a dozen lines with the requests library.
Q2Can I use this for automated testing?+
Yes — that's the primary use case. Read your key from an environment variable, create an inbox in a test fixture, trigger the email under test, then poll the inbox and assert on the subject, body, or extracted code. It works identically on your machine and in CI (GitHub Actions, GitLab, Jenkins), so email-dependent flows stop being flaky manual steps.
Q3How do I extract the OTP?+
Fetch the message with GET /api/message/{uid}?token={sessionToken} and run a regex over data.text (or data.html). A standard 6-digit one-time code matches the pattern \b(\d{6})\b. The step-3 snippet shows the full read-and-extract helper returning the code as a string.
Q4Do I need an API key, and are there rate limits?+
Every request requires the X-API-Key header, so you'll need a key from your EvilMail dashboard — keep it in an environment variable (EVILMAIL_KEY), never hard-coded. Reasonable rate limits apply per key to prevent abuse; when polling, the 3-second interval used in the examples stays comfortably within them. Check your plan for exact quotas.
Q5How long does the inbox live?+
You control it with the ttlMinutes value you pass when creating the inbox (30 minutes in the examples). Once the TTL expires the address and its messages are discarded, so create a fresh inbox per test run or task rather than reusing one long-term.
Temp mail in other languages
One API key. Disposable inboxes at scale.
Create unlimited throwaway addresses, poll them over HTTP, and pull verification codes straight into your tests and CI. Free to start; custom domains and higher limits on paid plans.

