Skip to content

Signing up for Discord? Some of our domains are accepted there. See which ones on the Domains page.

CyberTemp
All posts

How to Test Email Bounce Handling With a Disposable Inbox

CyberTemp5 min read

Need a disposable inbox right now?

Spin up a temporary email address in seconds — no signup, no spam, no trace.

Get a free inbox

Bounce handling is the part of a transactional email system nobody tests until a real hard bounce reaches production and the suppression list doesn't update. By then you've already re-sent a password reset to a dead mailbox three times, or worse, kept mailing a domain that's about to blocklist your sending IP. Testing this logic on purpose, before launch, takes one disposable inbox and a handful of deliberately broken addresses.

Hard bounce and soft bounce are not the same failure

A hard bounce means the address is permanently undeliverable — the mailbox doesn't exist, the domain doesn't resolve, or the recipient server rejected you outright with a 5xx code. Your system should suppress that address immediately. Sending to it again does nothing but damage your sender reputation.

A soft bounce is temporary — a full mailbox, a greylisting delay, a receiving server that's down for maintenance. That gets a 4xx code, and the correct response is a retry with backoff, not permanent suppression. A lot of transactional-email code treats every bounce the same way, either suppressing too aggressively (soft bounces get treated as hard, and real users lose password resets forever) or not suppressing at all (hard bounces get retried indefinitely, which is how sending domains end up on blocklists).

You can't verify which path your code takes just by reading it. You need to actually trigger both kinds of bounce and watch what your suppression table does.

Point your return path at a disposable inbox

Most transactional email setups configure a return-path or bounce-handling address that receives delivery status notifications (DSNs) when a send fails. In staging, swap that address for a CyberTemp inbox instead of a real mailbox you have to babysit:

# staging config
BOUNCE_ADDRESS = "[email protected]"

Then run your send pipeline against a small, deliberately broken address list — a nonexistent user at a real domain, a full mailbox if you have one to test against, a domain with no MX record, and one address that's correctly formatted but blocked by the receiving server's spam filter. Each of those triggers a different DSN, and each DSN lands in the same inbox where you can pull it with one call:

import httpx

API_KEY = "tk_..."
HEADERS = {"X-API-Key": API_KEY}
BASE = "https://api.cybertemp.xyz"

def get_bounce_notifications():
    r = httpx.get(
        f"{BASE}/getMail",
        params={"email": "[email protected]"},
        headers=HEADERS,
    )
    r.raise_for_status()
    return r.json()

No setup step is required before the first send — reading an address with GET /getMail creates the inbox if it doesn't already exist. Run the broken-address batch, wait a few seconds for the DSNs to land, then poll.

Reading the bounce code out of the DSN body

A DSN is a plain email with a machine-readable status code buried in it, usually in a Diagnostic-Code or Status field inside the message body. The pattern is consistent enough across mail servers that a regex gets you most of the way:

import re

def classify_bounce(message_body):
    match = re.search(r"(?:Status|Diagnostic-Code):.*?(\d)\d\d", message_body)
    if not match:
        return "unknown"
    code_class = match.group(1)
    if code_class == "5":
        return "hard"
    if code_class == "4":
        return "soft"
    return "unknown"

Run every DSN you pulled through this, and now you have ground truth: this address produced a hard bounce, that one produced a soft bounce. Compare that against what your application actually did with each address — did the hard-bounce address get suppressed, did the soft-bounce address get scheduled for retry instead of dropped. Any mismatch is a real bug, not a hypothetical one.

Building the test matrix

A useful bounce-handling test suite covers at least these cases, each aimed at a different failure mode in the receiving code:

  • Nonexistent mailbox at a valid domain — the standard hard bounce, should suppress on first failure

  • Nonexistent domain (typo'd TLD or unregistered name) — a different hard-bounce path, some codebases handle DNS failures separately from mailbox-not-found and miss one of the two

  • A mailbox that rejects for spam-policy reasons — often a 5xx that looks like a hard bounce but shouldn't necessarily suppress the address forever, since it's about content, not deliverability

  • A deliberately delayed or rate-limited receiving server, if you can arrange one — the soft-bounce case that should retry rather than suppress

Assert against your suppression table or event log after each run, not just against the DSN itself. The DSN tells you what the mail server said; the assertion tells you whether your code listened.

Wiring it into CI

This doesn't need to run on every commit — bounce logic changes rarely enough that a scheduled nightly run, or a check gated to PRs that touch the email-sending module, is enough. Generate a fresh bounce address per run so parallel CI jobs don't collide on the same inbox, tear the inbox down after asserting, and keep the broken-address list in version control next to the test so it's obvious what each case is supposed to prove.

If your CI runs enough of these in parallel that you're hitting per-key request limits, that's a plan-tier problem, not a test-design problem — CyberTemp's FREE tier is fine for occasional manual runs, but a CI pipeline generating fresh inboxes on every PR is exactly what the ECO, CORE, and ELITE tiers are built for.


Bounce handling is one of those systems that looks correct until the first real hard bounce proves otherwise. Testing it deliberately, with a disposable inbox standing in for the return-path address, catches the gap in staging instead of in a blocklist notice. See how wiring CyberTemp into signup-flow tests works if you haven't set up a similar pattern for OTP flows yet, and check handling rate limits and retries before you scale this up to a full CI matrix.

If you're scripting against signups — testing pipelines, multi-account workflows, automated QA, scrape-then-verify flows — the paid tiers are where per-key request limits stop being the bottleneck. Sign up if that's you.

Share
    How to Test Email Bounce Handling With a Disposable Inbox | CyberTemp Blog