blog
Best Practices for Managing Disposable Email Addresses
Manage private disposable email addresses through creation, receipt, expiry and deletion. Keep OTP and password-reset tests isolated and clean up safely.
A disposable email address is useful only while you can connect it to the task that created it. When a reset test fails, you need to know which inbox received the message, whether it belongs to the latest request, and what evidence will remain after cleanup.
Use a private inbox for each independent test identity. Keep it alive through the full application check, then remove what the test no longer needs. This guide explains those decisions for signup, OTP, invitation and password-reset workflows.
Give the address a clear owner
Create the inbox before asking the application to send. Store the inbox ID and email address together with the test run or workflow. The application uses the address as its recipient; MailSlurp's API uses the ID to retrieve that inbox's messages.
A descriptive name or tag can identify the environment and run without exposing a password or token. Use a stable run identifier, not just "test inbox", so a later cleanup task can distinguish its own resources from someone else's.
Use private account-controlled inboxes for access links, OTPs and customer-like test data. A disposable address keeps your personal mailbox out of the test; the word "disposable" alone does not guarantee privacy or anonymity.
Keep parallel tests from reading each other's mail
Give each independent user journey its own inbox. A test that resets one account should not compete with a second test for a shared "latest email" result.
Plus tags can help an application accept different address strings, but they may route into the same underlying mailbox. They do not automatically isolate messages or read state. The test-email-address guide explains when an alias, a private inbox or a format-only test value fits the job.
Keep the inbox assigned until the final application assertion. Reusing it halfway through verification makes a late delivery or a resend difficult to attribute.
Match the request, not just an unread message
Capture the time before requesting an email. Wait for a bounded period in the assigned inbox, and match the sender, expected subject and a request identifier where available.
A message can be unread and still belong to yesterday's run. A resend can also arrive with the same subject as the first request. If the application invalidates earlier links or codes, the test must use the current one rather than whichever message it encounters first.
After receipt, check the recipient and expected content. Validate a link's allowed origin and path before opening it. Keep OTPs as strings, including any leading zero. Finish by checking the intended account state, such as a verified user or a successful login with the new password.
Choose the inbox lifetime before the test starts
Allow enough time for setup, delivery, retries, the application flow and failure investigation. Set a lifetime longer than the test's maximum runtime so the inbox does not close while the test still needs it.
MailSlurp supports expiresIn for a duration in milliseconds or expiresAt for a specific timestamp. In the JavaScript SDK, expiresAt accepts a Date object. The temporary email API explains the settings and longer-lived workflows.
The application's token has a separate lifetime. Keeping an inbox open does not make an expired reset link valid, and an inbox expiry setting does not test your application's OTP expiry rule.
Distinguish expiry from deletion
MailSlurp periodically archives inboxes whose expiry time has passed. Once archived, the address can no longer send or receive, while existing emails can remain. Verify the archived state through the expired-inbox API when testing expiry itself; reading a configured timestamp only proves the setting.
For cleanup, decide what to retain, delete the intended resources explicitly, and check the result. Keep these actions separate:
- Inbox expiry: schedule the address to close to future sending and receiving.
- Message or inbox deletion: remove test data according to the workflow's retention policy.
- Application cleanup: remove or reset the test user, invitation, order or other application record.
Deleting an inbox does not clean your application's database. Likewise, an inbox ID in a log does not preserve the email after deletion.
Save useful failure evidence without exposing tokens
Capture enough information to locate the failure: test name, inbox ID, message ID, send and receive times, and the assertion that failed. Those details often show whether the app failed to send, the wait matched the wrong request, or verification failed after receipt.
Keep message bodies, reset links and OTPs out of general build logs. If a failed test needs a message or screenshot retained, store it with the access and retention controls your team uses for test data. Save it before deleting the underlying inbox.
For a visual defect, device previews can help isolate the affected client. Receipt and appearance are separate checks: a delivered verification email can still have an unreadable button or missing logo on a phone.
Make cleanup run after failures too
Use your framework's teardown or a finally path so a failed assertion still triggers cleanup. Preserve the original test failure, and report any cleanup failure as well. Silently swallowing deletion errors leaves resources behind without telling the person reviewing the run.
Scope cleanup to the IDs created by that test or to a clearly identified expired run. Avoid account-wide deletion in a reusable helper. Another test, reviewer or scheduled workflow may still need its inbox.
An interrupted process may never reach teardown. Scheduled expiry provides a fallback when the server archives the inbox; a separate cleanup routine can reconcile leftover resources and retained data. Check what actually remains instead of assuming the scheduled work succeeded.
Follow a complete example
The parallel password-reset example creates isolated inboxes with expiry configured, receives real MailSlurp messages and completes two account flows. It also rejects an older reset link, checks the final signed-in identities and explicitly deletes its inboxes during teardown.
Use the downloadable source to see how the fixture keeps ownership, message matching, application assertions and teardown together. Configuring expiry and explicitly deleting an inbox are separate steps; do not treat one as a test of the other.
For a first manual check, create a private test address. For API setup, use the disposable email API and keep the same inbox ownership rules as the workflow grows.