Email verification tests are deceptively easy to make green. A Docker job starts, creates a user, waits for a message, and checks that a link arrived. The problem begins when the inbox is shared: an old message can satisfy the new test, or two parallel jobs can read each others evidence.

I treat email fixtures as run-scoped infrastructure. Every CI run gets an identity, a bounded lifetime, and a cleanup owner. The email service can be a fake email generator or a small internal test adapter, but the control plane belongs in the pipeline. This makes failures more boring to investigate, which is exactly what I want from CI.

Why shared email fixtures break CI

A shared test inbox creates several failure modes:

  • A previous verification message is still present.
  • Parallel Docker jobs receive similar messages and race to consume them.
  • A retry reads the first attempt's message and reports a false success.
  • Cleanup is manual, so abandoned addresses and messages accumulate.

The visible failure may be in the application, but the root cause is often identity. The test knows the expected recipient, yet it does not know whether the message belongs to this run. That is not a good enough contract.

I have found run tokens for less fragile email CI useful as a simple mental model: the run token must travel with the fixture and with the assertion.

Give every Docker job an identity

Create one stable ID before the test container starts. For GitHub Actions, I normally combine the repository, workflow run, and attempt:

RUN_ID="${GITHUB_REPOSITORY##*/}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" RUN_ID="$(printf '%s' "$RUN_ID" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9-')" echo "EMAIL_RUN_ID=$RUN_ID" >> "$GITHUB_ENV" 

Pass the value to Docker and to the fixture adapter:

docker run --rm \ -e EMAIL_RUN_ID="$EMAIL_RUN_ID" \ -e EMAIL_FIXTURE_TTL_SECONDS=900 \ app-e2e:${GITHUB_SHA} 

The adapter should derive a unique mailbox or alias from EMAIL_RUN_ID, rather than selecting a random address that cannot be traced later. Store the run ID, creation time, expiry time, and current status beside the fixture. A small record is enough; the full email body usually is not.

Do not put secrets in the address or in the subject. The run ID is correlation data, not an access token. If the workflow also tests OAuth, an identity boundary for OAuth redirect tests is a related safeguard: the test identity should be explicit and disposable, not inherited from a developer session.

Keep the AWS pipeline run-scoped

In AWS, the cleanest arrangement I have used is to keep fixture lifecycle next to the CI job, while storing only redacted results in the build artifact. The test runner can call the fixture adapter through a private endpoint, and the adapter can apply the lease and expiry policy.

The pipeline should have three distinct phases:

  1. Provision: create or claim the fixture using the run ID.
  2. Assert: poll until the expected event arrives, with a deadline.
  3. Reconcile: consume or expire the fixture, even when the test fails.

Make the reconcile step unconditional. In GitHub Actions that means using a final cleanup step with if: always(). In another runner it may be a post-job hook. The exact syntax matters less than the guarantee that a failed assertion does not leave a live fixture behind.

Use separate outcomes such as matched, expired, wrong_run, and provider_error. A single email_failed status sends the next engineer searching the wrong layer. The test are easier to debug when the result says whether no message arrived or the wrong message arrived.

Verify the message, not just the inbox

The assertion should check all of the following:

  • recipient or fixture ID matches the current run;
  • event type is the one being tested;
  • message was created after the fixture lease began;
  • token or link is associated with the test user;
  • message has not already been consumed by a retry.

A subject search alone is too weak. Providers may normalize subjects, and a copied subject can look valid. Prefer structured metadata when the adapter supports it. If only message text is available, include a short run marker and validate it together with the recipient and user ID.

Poll with a deadline and bounded backoff. The first request can be quick, then the delay can grow modestly. Avoid an unbounded loop: a CI job that waits forever is harder to operate than one that reports expired after a clear timeout. A few extra seconds is cheaper then diagnosing a pipeline that never finishes.

Retain useful evidence and clean up

Keep a small JSON result in the CI artifact:

{ "run_id": "web-1842-1", "fixture_status": "consumed", "event": "verification", "message_id_hash": "sha256:...", "created_at": "2026-12-04T02:00:00Z", "received_at": "2026-12-04T02:00:08Z", "result": "matched" } 

Hash identifiers where possible and redact message bodies. The logs is more useful when it can be shared without exposing addresses, tokens, or personal data. Retain the Docker image digest and deployment revision too; those fields connect email evidence to the exact application under test.

Cleanup must be idempotent. Running it twice after a runner restart should still be a success. Measure cleanup failures as well, because an abandoned fixture is a small leak that becomes an operations problem at scale. Search strings like temp gamil com or temp mailid may appear in malformed-input tests; keep them as test data, never as proof that a fixture is owned by the current run.

Final checklist

  • Create one stable identity before starting the Docker test.
  • Bind the fixture to that identity and an expiry time.
  • Pass the identity through AWS CI and into the assertion code.
  • Match recipient, event, timestamp, user, and consumption state.
  • Return distinct timeout, wrong-run, and provider failure states.
  • Run cleanup on success, failure, and cancellation.
  • Keep redacted evidence with the build artifact.
  • Track cleanup failures and fixture age.

The payoff is a green build that means the current run received the expected evidence. It does not merely mean some verification email happened to be waiting in a shared inbox.