docs: add a guide for testing emails with AgentMail (ENG-1578)

Merged
SA
2d ago
+240-0

What

  • A new "Guides" group in the docs sidebar with a "Test emails with AgentMail" page (/guides/agentmail). The page shows a test that creates a new AgentMail inbox, signs up with its address, and reads the email the app sends to it. await using deletes the inbox when the test ends.

Why

Users who test sign-up or password-reset flows need to read the email their app sends. AgentMail lets each test get its own real inbox, so the test reads only its own email. The group is called "Guides" rather than something about email so that guides for other kinds of services can go in it later.

Another open PR creates the same "Guides" group. Whichever merges second will need the group's pages entries merged in docs/docs.json, plus the entries in docs/package.json, pnpm-lock.yaml and scripts/check-docs-examples.ts.

How it works

  1. docs/docs.json adds the "Guides" group after "Hosted browsers and devices", with the book-open icon like the other groups in that tab.
  2. The code on the page lives in docs/examples/agentmail/. The docs typecheck covers it, and scripts/check-docs-examples.ts maps each file to the page, so the page copy can't drift. docs/package.json adds agentmail@0.5.54 for the typecheck.
  3. The example test (docs/examples/agentmail/tests/signup.e2e.ts) has a createInbox() helper. It creates the inbox with a random clientId, so a create the SDK retries after a 5xx returns the same inbox instead of a second one. It returns the inbox with a Symbol.asyncDispose method that deletes it, and the test declares it with await using. e2e compiles test files and turns using into code Node 22 can run, so this works on the Node 22 floor. A fixture or try/finally would also work. The helper keeps the example in one file.
  4. The test signs up with the inbox's address, waits in toPass({ timeout: 60_000 }) until messages.list() returns one message, then checks its subject and HTML with messages.get(). AgentMail SDK calls throw on error, so toPass() retries and fails with the last error. The timeout sits below the default 120 s test timeout. If the email never arrives, the test fails on the assertion and the inbox is deleted. A test that hits the test timeout is abandoned, so its delete might not finish. The page says to keep the wait below the test timeout.
  5. The config (docs/examples/agentmail/e2e.config.ts) registers AGENTMAIL_API_KEY with registerProviderKey, so e2e redacts it. The app sends the email through its own provider, which the example leaves out. The text under the config says to pass that provider's key with inheritEnv and register it too. Without the key, the app can't send, and the test waits for an email that never arrives.
  6. The Limits section covers the per-plan inbox cap (3 on the free plan, existing inboxes included). inboxes.create() fails with a 403 when the cap is reached.

Choices a fresh-context review questioned that I kept:

  • The page is a tutorial in the inclusive "we" voice, with an "In this guide, we ..." sentence and an "Installation" heading. The page owner chose this voice, so the authoring-docs rules that say otherwise don't apply here.
  • The vendor logo and overview card rules cover integrations, CI services and migration guides. A guide is none of those, so it has no logo or card.
  • If the process is killed before the test ends, the inbox stays. The Limits section explains why that matters.

Verified

Ran it locally: yes

  • pnpm check passes on this branch. pnpm test and the default testbed suite passed on the combined branch before the split, and this branch changes only docs.
  • The example test, copied unchanged into a scratch project. It ran against the real AgentMail API, with a sign-up page that sends from a verified domain. The account had 1 inbox before the runs and 1 after each run below, so the inbox is deleted every time:
    • a passing run with the clientId, 5.16 s
    • a run where I forced the subject assertion to fail (before the clientId and toPass timeout were added)
    • a run where the app's send was refused, so no email arrived: ASSERTION_FAILED: expect(...).toPass() timed out after 60000 ms at 62.19 s
 ✓ |web| tests/signup.e2e.ts > signing up sends a welcome email 5.16s
 Tests  1 passed (1)
  • I didn't capture screenshots of the rendered page because there's no local docs renderer. The docs preview deploy on this PR shows it.
  • Shortening pass: the page is new, at 146 lines. It doesn't say a fact twice, so I made no cuts.

Summary by CodeRabbit

  • Documentation
    • Added an AgentMail guide under “Hosted browsers and devices,” with setup instructions and an example of testing signup confirmation emails.
    • Documented inbox limits, including the free-plan limit of three simultaneous inboxes, and the error returned when no inbox slot is available.
    • Noted that tests send real email through the configured provider and count toward its quota, and that timeouts may interrupt inbox cleanup.
    • Added the guide’s configuration and signup test examples to documentation checks, including temporary inbox creation and cleanup.