I keep seeing the same failure pattern in email automation: the test passes locally, gets weird in CI, and then somebody adds a sleep plus one more retry. That helps for a day, maybe two. The deeper problem is usually simpler. The workflow is selecting "the latest email" instead of proving the email belongs to the current run.
This matters whether your team uses a disposable mail address for preview tests, a shared staging inbox, or a purpose-built mail helper. Once multiple jobs run at the same time, "latest" stops meaning much. It starts meaning "whatever arrived most recently in a noisy system," which is not the same thing at all.
I have had the best results with one boring rule: every email-producing test gets a run token, and every assertion checks for it before opening a link. It sounds small, but it removes a suprising amount of guesswork.
Why "latest email" is a risky test strategy
The brittle version of an email test usually looks like this:






