Skip to main content

Login Code Flow

Use a fresh inbox and an after timestamp.
const inbox = await mail.inbox({ new: true });

await page.getByLabel("Email").fill(inbox.emailAddress);

const after = new Date();
await page.getByRole("button", { name: "Send code" }).click();

const message = await inbox.waitForMessage({ after });
Then extract the code from the parsed message.
const match = message.text.match(/\b\d{6}\b/);

if (!match) throw new Error("Login code email did not contain a 6-digit code");

await page.getByLabel("Code").fill(match[0]);
await page.getByRole("button", { name: "Verify" }).click();
This pattern avoids reading an older login email from the same address. For wait options and parsed message fields, see the Mail Reference.
Last modified on April 24, 2026