Guide

OTP email testing in CI: a practical guide

Email is slow and asynchronous, which is why email tests flake. A few rules make them dependable.

Updated 2026-10-02 · Emailsify

Rules that remove flakiness

  1. One inbox per test. Never share addresses between tests.
  2. Wait for the message, never sleep for a fixed time.
  3. Set a timeout that reflects real delivery times, then fail with a useful message.
  4. Filter by sender or subject so stale mail cannot match.
  5. Assert on the extracted code or link, not on the whole email.

What to log

  • The generated address.
  • The time you triggered the email and the time it arrived.
  • The subject of the message you matched.

Frequently asked questions

What timeout should I use?

Start with 30 to 60 seconds and tune from your measured delivery times.

Keep reading