docs: add a guide for testing emails with AgentMail (ENG-1578)
Merged
SA
2d ago+240+240+012345678901234567890123456789-0-0-0123456789
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 usingdeletes 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
docs/docs.jsonadds the "Guides" group after "Hosted browsers and devices", with thebook-openicon like the other groups in that tab.- The code on the page lives in
docs/examples/agentmail/. The docs typecheck covers it, andscripts/check-docs-examples.tsmaps each file to the page, so the page copy can't drift.docs/package.jsonaddsagentmail@0.5.54for the typecheck. - The example test (
docs/examples/agentmail/tests/signup.e2e.ts) has acreateInbox()helper. It creates the inbox with a randomclientId, so a create the SDK retries after a 5xx returns the same inbox instead of a second one. It returns the inbox with aSymbol.asyncDisposemethod that deletes it, and the test declares it withawait using. e2e compiles test files and turnsusinginto code Node 22 can run, so this works on the Node 22 floor. A fixture ortry/finallywould also work. The helper keeps the example in one file. - The test signs up with the inbox's address, waits in
toPass({ timeout: 60_000 })untilmessages.list()returns one message, then checks its subject and HTML withmessages.get(). AgentMail SDK calls throw on error, sotoPass()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. - The config (
docs/examples/agentmail/e2e.config.ts) registersAGENTMAIL_API_KEYwithregisterProviderKey, 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 withinheritEnvand register it too. Without the key, the app can't send, and the test waits for an email that never arrives. - 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 checkpasses on this branch.pnpm testand 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
clientIdandtoPasstimeout were added) - a run where the app's send was refused, so no email arrived:
ASSERTION_FAILED: expect(...).toPass() timed out after 60000 msat 62.19 s
- a passing run with the
✓ |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.