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 Attachment Handling Without Risking Your Real 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

Attachment handling is the part of an email pipeline that almost nobody scripts a test for. Teams verify subject lines, verify that a link fires, verify that HTML renders — and then ship a PDF invoice or a CSV export attachment with a broken filename, a missing MIME type, or a silently dropped file, because the only "test" was someone eyeballing their own inbox once.

Why attachment bugs slip through

Attachments break in ways that don't show up in a rendering check. A generated PDF can be zero bytes because the render job timed out. A CSV export can get the wrong content type and open as garbage text in some clients. A zipped report can trigger a provider's malware scanner and get stripped entirely, leaving the recipient with an email that looks normal but has nothing attached. None of that is visible unless something actually opens the file that arrived.

The reason it gets skipped is logistics, not laziness. Testing an attachment properly means sending real mail to a real inbox, downloading what comes back, and inspecting the file — and most QA setups don't have a disposable inbox sitting around that's safe to point a CI job at. So the check gets replaced with "the email sent successfully" logging, which tells you the send succeeded and nothing about what showed up.

What to actually verify

  • The attachment exists at all — some failure modes (render timeout, malware-scan strip) produce a normal-looking email with zero attachments.

  • The filename is what you expect — invoice numbers, dates, and customer names get concatenated into filenames, and encoding bugs turn those into garbled strings in some clients.

  • The file opens and isn't truncated — a connection drop mid-upload can produce a partial file that still passes a "did it attach" check.

  • The content type matches the file — a CSV served as application/octet-stream downloads fine in some clients and prompts a "what do you want to do with this" dialog in others.

A disposable inbox built for this

The fix is to give the test a real inbox that isn't tied to anyone's actual mailbox. Generate one address per test run, trigger the flow that sends the attachment, poll the inbox for the message, and then treat the message body the same way you'd treat any other API response — assert on it directly instead of trusting the send log.

A per-run address also means test runs don't collide. Name it by run ID or timestamp — something like [email protected] — so two CI jobs firing at the same time aren't reading each other's mail.

Polling for the message and checking the attachment

CyberTemp's API is flat enough that this fits in a short script. There's no separate "create inbox" call — reading an address for the first time creates it, so you generate the address, send your test email to it, and poll until the message shows up.

import time
import requests

API_KEY = "tk_your_key_here" INBOX = "[email protected]"

def poll_for_message(timeout=30, interval=2): deadline = time.time() + timeout while time.time() < deadline: r = requests.get( "https://api.cybertemp.xyz/getMail", params={"email": INBOX}, headers={"X-API-Key": API_KEY}, ) r.raise_for_status() messages = r.json() if messages: return messages[0] time.sleep(interval) raise TimeoutError(f"no message arrived for {INBOX}")

message = poll_for_message()

assert "invoice" in message["subject"].lower(), "wrong subject, wrong template fired" assert message.get("attachments"), "no attachment arrived — check the render job"

attachment = message["attachments"][0] assert attachment["filename"].endswith(".pdf"), f"unexpected filename: {attachment['filename']}" assert attachment["size"] > 1000, "file looks truncated"

Wrap that in whatever test runner you already use and you've turned "did the attachment send" into an assertion instead of a hope. Run it against every template that generates a file — invoices, export reports, signed contracts — and you catch a broken render job in CI instead of in a support ticket.

Wiring it into CI without flaking

Two things make this reliable instead of flaky. First, poll with a real timeout and backoff rather than a fixed sleep — mail delivery isn't instant, and a hardcoded three-second wait will fail intermittently under load. Second, delete the inbox at the end of the run with DELETE /inbox so a long-running CI pipeline doesn't accumulate hundreds of test addresses against your plan's inbox limit. If you're running a lot of parallel suites, that limit is exactly what separates the plan tiers — FREE covers the occasional local run, while ECO, CORE, and ELITE raise the concurrent-inbox ceiling for teams running attachment checks on every merge. The plan-picking guide covers how to match tier to workload if you're not sure which one fits.

This same pattern extends past attachments. If you're already testing calendar invite files or chasing down rendering bugs, attachment verification is the same disposable-inbox setup pointed at a different assertion.

Bottom line

If your product emails a file to anyone — a receipt, an export, a signed document — that file deserves the same test coverage as the rest of the flow. A disposable inbox makes that cheap enough to run on every merge instead of once before launch. Generate an address at cybertemp.xyz, send your attachment through it, and check what actually arrives instead of trusting that it did.

Share
    How to Test Email Attachment Handling Without Risking Your Real Inbox | CyberTemp Blog