Testing Email Verification in Playwright with a Free Disposable Inbox (No Signup, No API Key)
Most Playwright suites stop right before the hard part of a signup flow: the "confirm your email" link, the emailed 6-digit code, the password-reset mail. The usual reasons are that you need a real inbox your test can read, and every option seems to want an account, an API key, or a paid plan. This post shows how to test those flows end to end with a disposable inbox that needs no signup and no…
Testing email verification in Playwright can be challenging as most test suites stop before the crucial email verification step. The typical reason for this is the need for a real inbox that the test can read, which usually requires an account, an API key, or a paid plan. This article demonstrates how to perform end-to-end email verification testing with a disposable inbox that requires neither an account nor an API key.
The service named receivemail.dev was built and the accompanying Playwright fixture used in the article for this specific purpose. The principle is simple: create a brand-new inbox for each test, ensuring no shared state or stale mail from previous runs. Sign up in the application using this unique email address, then monitor the inbox until the expected email arrives within a specified timeout. Extract the verification link or code from the email body and complete the verification flow.
To get started, install playwright-receivemail and @playwright/test as dependencies. The test fixture provides a mailbox for each test, generating a fresh @receivemail.dev address. Import the necessary functions and create a test case where you navigate to the sign-up page, fill in the email and password fields using the mailbox address and a predefined password, respectively.
Click the "Create account" button, wait for the verification email to arrive, extract the verification link from the email body, navigate to it, and verify that the "Email verified" text is visible.
The same process can be applied to test OTP (one-time password) code verification. In this case, extract the 6-digit code from the email and fill it into the verification field. The mailbox polling mechanism polls every 2 seconds by default with a 30-second timeout, which can be adjusted based on your application's configuration. Mailboxes live for 15 minutes by default, providing ample time for CI runs, but the TTL (Time To Live) can be configured between 1 to 60 minutes.
The fixture works similarly across various test runners, including Cypress, Jest, or any shell script. It retrieves the necessary data using two HTTP calls to receivemail.dev, with the secret (bearer token) obtained during inbox creation. Cypress users can benefit from the cypress-receivemail plugin, which provides createMailbox and waitForEmail functions. However, keep in mind that this is designed for test environments and not for long-term retention or SLA requirements. Paid services should be used for that purpose.
For more information, visit receivemail.dev for the inbox API, install playwright-receivemail via npm, and explore cypress-receivemail on npm. If you decide to try this out, feedback on any issues or missing features would be appreciated.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.