Skip to main content

Developer API for automated signups

See the API

Automate Signup Testing With a Temp Mail REST API and Python SDK

Developer

By the zephbox teamPublished Updated 4 min read

How we write these: product details are checked against the current zephbox API and site behavior on the date shown. Spotted a mistake? Tell us and we correct it (editorial policy).

You can automate signup testing with nothing but requests, and for a quick script that is enough. Once the same create-wait-extract sequence appears in more than a couple of tests, the zephbox Python SDK removes the boilerplate: one client object, one method per endpoint, and a single exception type to assert on. This guide builds the same test three ways, from raw HTTP to a pytest fixture, using only calls that exist in the API and SDK.

Prerequisites

Version 1: raw HTTP

import os, requests

BASE = "https://zephbox.com/api/developers"
H = {"X-API-Key": os.environ["ZEPHBOX_API_KEY"]}

inbox = requests.post(f"{BASE}/aliases/", headers=H, timeout=10)
inbox.raise_for_status()
alias = inbox.json()["alias"]

# ... submit your signup form with `alias` ...

r = requests.get(f"{BASE}/aliases/{alias}/wait-for-otp/",
                 params={"timeout": 20}, headers=H, timeout=25)
r.raise_for_status()               # 408 = nothing arrived in time
code = r.json()["code"]

Note the client timeout (25) is larger than the server wait (20). If your HTTP timeout is shorter than the wait, you will see a client-side error instead of the API's clean 408.

Version 2: the SDK

from zephbox import ZephboxClient, ZephboxAPIError
import os

client = ZephboxClient(api_key=os.environ["ZEPHBOX_API_KEY"])

inbox = client.create_inbox()            # dict, address in inbox["alias"]
alias = inbox["alias"]

# ... submit your signup form with `alias` ...

try:
    result = client.wait_for_otp(alias, timeout=20)
except ZephboxAPIError as e:
    raise AssertionError(f"No verification mail: {e.status_code} {e.detail}")

print(result["code"], result["link"], result["sender"])
client.delete_inbox(alias)

Every non-2xx response becomes a ZephboxAPIError carrying status_code and detail, so a test can distinguish "timed out" (408) from "not allowed on this plan" (403) without parsing text. The client also has read_inbox(alias) to list messages, get_otp(alias) to extract from mail that already arrived, and create_and_wait_for_otp(timeout), which creates an inbox and waits for its first message in one call. Be careful with that last method: it blocks until mail arrives and only then returns the address, so your own code never sees the address in time to submit a signup with it. It is useful only when something else already knows how to trigger the email; for a normal test, create the inbox first, as above.

Version 3: a pytest fixture

import os, pytest
from zephbox import ZephboxClient

@pytest.fixture(scope="session")
def zephbox():
    return ZephboxClient(api_key=os.environ["ZEPHBOX_API_KEY"])

@pytest.fixture
def inbox(zephbox):
    box = zephbox.create_inbox()
    yield box["alias"]
    zephbox.delete_inbox(box["alias"])      # tidy even if the test failed

def test_signup_sends_working_code(inbox, zephbox, app_client):
    app_client.signup(email=inbox)          # your app's signup call
    otp = zephbox.wait_for_otp(inbox, timeout=20)
    assert otp["code"], f"no code in mail from {otp['sender']}: {otp['subject']}"
    assert otp["sender"].endswith("@yourapp.example")
    app_client.verify(email=inbox, code=otp["code"])
    assert app_client.login(email=inbox).ok

Three details make this robust. The fixture deletes the inbox in teardown, so failed runs do not leave addresses behind. The test asserts the sender, so an unrelated message cannot pass it. And the last line asserts the real outcome, a working login, instead of stopping at "a code was found".

Running it from the command line

The package also installs a zephbox command that reads ZEPHBOX_API_KEY. It is handy for debugging a flaky flow by hand:

zephbox create                         # prints the new inbox as JSON
zephbox wait <alias> --timeout 20      # block until the next message
zephbox otp <alias>                    # extract from mail already there
zephbox inbox <alias>                  # list messages
zephbox delete <alias>

Common mistakes

Error reference for test code

These are the responses a test should expect from the inbox and OTP endpoints, based on how the API is implemented:

StatusMeaningWhat to do
401Missing, invalid, revoked or expired API key (the message says which)Rotate the key; check CI secrets
403The account is not on a plan that allows this endpointUpgrade or use a different account
404Alias not found, or (on /otp/) no message has arrived yetWait, or check the alias string
408wait-for-otp timed outRead the inbox, then fail with context
429Rate limit reachedBack off; reduce parallel waits

Running several signups in parallel

Each worker should own its own inbox, so there is no shared state to race on:

from concurrent.futures import ThreadPoolExecutor

def run_one(i):
    box = client.create_inbox()
    try:
        app.signup(email=box["alias"], username=f"qa-user-{i}")
        return client.wait_for_otp(box["alias"], timeout=20)["code"]
    finally:
        client.delete_inbox(box["alias"])

with ThreadPoolExecutor(max_workers=3) as pool:
    codes = list(pool.map(run_one, range(3)))

Keep the worker count low. Every in-flight wait holds a server connection and long-poll calls are throttled separately from ordinary requests; for large parallel suites, use webhooks instead (comparison).

When this is not the right tool

Disposable addresses are for receiving. If your flow needs the test user to send an email, or you need to test deliverability into specific providers like a real Gmail account, you need other tooling. And if you are driving the flow from an AI agent rather than a test runner, see the MCP server, which exposes the same capability as agent tools. The complete reference is in the API docs.

Frequently asked questions

Is the SDK required?

No. It is a thin wrapper over the REST API, so any HTTP client works. The SDK saves you repeated error handling and gives you one exception type.

What does ZephboxAPIError contain?

The HTTP status code and the API's own error detail, so tests can tell a 408 timeout from a 403 plan restriction.

How long does the wait call block?

Up to 20 seconds per call; the default is 15. For slower senders, call it again rather than increasing a sleep.

Private Disposable Inboxes & Developer API

Run multiple addresses, custom usernames, forwarding, and automated OTP extraction with Full Access.

Try zephbox Premium →

Related guides

← Generate a temporary email now
zephboxDeveloper API for automated signups
Learn more about the zephbox developer API