rc.center Learnrc.center Learnrc.center

Testing password reset and magic link e-mails end to end

Published on 5 min readOTPBox

Automate password reset and magic link login tests against real e-mail: request the mail, read the link with a time filter, check its host and finish the flow.

Key and link chain shapes flowing into an envelope, drawn in violet light on a dark background

Password reset and magic link login are the flows users reach for when something is already wrong. They are also the ones teams test least, because the critical step happens in an inbox. This guide automates both with a real receiving address from OTPBox, so the test proves the mail is sent, arrives, and contains a link that works.

What makes these flows hard to test

Three things differ from a plain sign-up test.

The inbox already has mail. The user signed up earlier, so the inbox holds a welcome or verification message. A naive “read the latest e-mail” can pick up the wrong one.

The link is the whole point. A reset mail usually carries a single-use link rather than a code, and the test needs to know the link goes to the right host for the environment.

Timing matters. Links expire and are single use, and you want tests for that too.

Setup: one inbox per test user

Create a dedicated inbox for the test user and keep its id with the user fixture. With an API key from the OTPBox web app in OTPBOX_KEY:

curl -s -X POST https://otpbox.rc.center/v1/inboxes \
  -H "Authorization: Bearer $OTPBOX_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"prefix":"reset-user"}'
{
  "id": "<inbox-id>",
  "address": "reset-user.k3m9qa@<account>.otpbox.org",
  "domain": "otpbox.org",
  "created_at": "2026-10-20T18:20:37Z"
}

Sign the user up with that address (or reuse the inbox from your sign-up test) before the reset test runs.

Password reset with curl

Trigger the reset in your app, then wait for the mail. Record the time just before you trigger it:

SINCE=$(date -u +%Y-%m-%dT%H:%M:%SZ)

# trigger the reset in your app, for example:
curl -s -X POST https://staging.example.com/api/password-reset \
  -H 'Content-Type: application/json' \
  -d '{"email":"reset-user.k3m9qa@<account>.otpbox.org"}'

curl -s "https://otpbox.rc.center/v1/inboxes/<inbox-id>/wait?timeout=60&since=$SINCE&expect_domain=example.com&subject=reset" \
  -H "Authorization: Bearer $OTPBOX_KEY"
{
  "found": true,
  "sender_auth": "pass",
  "from_address": "no-reply@example.com",
  "codes": [],
  "verify_link": "https://staging.example.com/reset?token=<token>",
  "verify_link_host": "staging.example.com",
  "verify_link_suspicious": false,
  "message": {
    "id": "<message-id>",
    "subject": "Reset your password",
    "received_at": "2026-10-20T18:21:04Z",
    "state": "ready"
  }
}

verify_link is the link OTPBox classified as the action link of the message. Its classifier treats verification, confirmation, magic login, reset and activation links as the same kind, and keeps unsubscribe links and everything else apart. To see every link with its kind and real host, fetch the message:

curl -s https://otpbox.rc.center/v1/messages/<message-id> \
  -H "Authorization: Bearer $OTPBOX_KEY"

The links array in that answer looks like this:

[
  { "url": "https://staging.example.com/reset?token=<token>", "text": "Reset password", "kind": "verify", "host": "staging.example.com" },
  { "url": "https://example.com/help", "text": "Help center", "kind": "other", "host": "example.com" },
  { "url": "https://example.com/unsubscribe?u=<id>", "text": "Unsubscribe", "kind": "unsubscribe", "host": "example.com" }
]

A link also carries mismatch: true when its visible text names a different site than the one it goes to, which is worth asserting against in a template test.

The since filter: getting the right message, not the newest old one

The wait endpoint returns the newest message that matches the filters. Without since, it looks back 10 minutes. If the sign-up mail arrived 2 minutes ago and you wait with no filters, it returns the sign-up mail immediately, and the test reads the wrong link.

Two ways to avoid that, and they combine well:

  • Pass since with the time you triggered the reset (RFC 3339, UTC). Only messages received after it count.
  • Narrow by content with subject (a case-insensitive substring) or regex (an RE2 expression matched against the subject and the text).

Allow for clock skew between your test runner and the server. Taking the timestamp a couple of seconds before the trigger is a safe habit.

Password reset in a Playwright test

The same flow in a browser test, with a small helper for the REST calls (see the Playwright guide for the full helper):

import { test, expect } from '@playwright/test';
import { waitForMessage } from './support/otpbox.js';

test('a user can reset the password from the e-mail link', async ({ page }) => {
  test.setTimeout(120_000);
  const { inboxId, address } = testUser; // created and signed up earlier

  const since = new Date(Date.now() - 2_000).toISOString().replace(/\.\d{3}Z$/, 'Z');

  await page.goto('https://staging.example.com/forgot-password');
  await page.getByLabel('E-mail').fill(address);
  await page.getByRole('button', { name: 'Send reset link' }).click();

  const mail = await waitForMessage({ inboxId, timeout: 60, since, expect_domain: 'example.com', subject: 'reset' });

  expect(mail.found).toBe(true);
  expect(mail.verify_link_host).toBe('staging.example.com');

  await page.goto(mail.verify_link);
  await page.getByLabel('New password').fill('another-long-test-password');
  await page.getByRole('button', { name: 'Save' }).click();
  await expect(page.getByText('Password updated')).toBeVisible();
});

A magic link test is the same shape with a different trigger, and often a code as well as a link. OTPBox extracts both: codes lists the one-time code candidates best first (plain digits, digits split into groups such as 739 214, or letters and digits such as XK7-2PQ), and skips numbers that look like prices, dates, phone or order numbers, and verify_link holds the login link.

const since = new Date(Date.now() - 2_000).toISOString().replace(/\.\d{3}Z$/, 'Z');

await page.goto('https://staging.example.com/login');
await page.getByLabel('E-mail').fill(address);
await page.getByRole('button', { name: 'E-mail me a login link' }).click();

const mail = await waitForMessage({ inboxId, timeout: 60, since, expect_domain: 'example.com' });

expect(mail.found).toBe(true);
await page.goto(mail.verify_link);
await expect(page.getByText('Signed in as')).toBeVisible();

If your app offers “enter this code instead”, run the same test with mail.codes[0] typed into the code field. Testing both paths catches templates where one of them was dropped.

An AI agent connected over MCP does the same with message_wait, which takes the same filters:

message_wait {"inbox_id": "<inbox-id>", "timeout_seconds": 60, "since": "2026-10-20T18:21:00Z", "expect_domain": "example.com"}

Negative cases worth automating

Once the happy path works, the real inbox makes the less common checks easy.

The link is single use. Open verify_link twice and assert the second visit shows an expired or used message.

The old link stops working. Request two resets, wait for each with its own since, then open the first link and assert it is rejected.

No mail for unknown users. Request a reset for an address that has no account (create a fresh inbox for it), wait with a short timeout, and assert found is false. This checks you do not send mail that confirms whether an account exists, if that is your policy.

The mail is authenticated. Assert sender_auth is pass in environments that send from a domain with a DMARC policy. A change of provider or a DNS edit that breaks SPF or DKIM shows up here before users notice.

Checklist

  • One inbox per test user, kept for the user’s lifetime in the test suite, deleted when the suite tears down.
  • Take a timestamp before each trigger and pass it as since.
  • Filter with expect_domain and subject so only the expected mail counts.
  • Assert on verify_link_host, not only on the presence of a link.
  • Keep within the plan limits: on rc.center Pro, 20 active inboxes and 30 received messages per minute for the whole account, with messages kept for 30 days unless you delete them sooner.