Developer Guide: Testing Email & Webhook Flows with Disposable Mail Addresses

Overview of how software developers and QA engineers can utilise inboxes to ensure transactional email flows such as signups, verification codes and SMTP webhook integration are properly tested.

Engineering Team

Developer Guide: Testing Email & Webhook Flows with Disposable Mail Addresses

When developing web applications, you'll often have to pay close attention to your transactional email flows. Whether you're sending MFA codes, user signup confirmations, auto generated invoices and password reset tokens - they're all critical pieces of information. Unfortunately, testing these emails during development and CI can cause issues for your engineering team.

This guide highlights why traditional testing methods aren't suitable, how to integrate temporary mailboxes into your automated testing suites and finally how to test end to end user onboarding flows without causing any production database pollution.


1. Common Issues With Email Testing In Staging

Frequently software teams will implement one of the following:

  • Personal Engineer Accounts: Using the engineer's personal Gmail/Outlook account to send emails quickly fills up the inbox and makes it impossible to run automated regression tests.
  • Mock Data Hardcoded: Whilst the mock email service will return a success status confirming your app has made the call to the email API SDK, it won't check anything related to the actual email being delivered to the SMTP server, DNS MX records and if the dynamic HTML templates are rendering properly.
  • Team Shared Emails: Using one shared mailbox e.g [email protected] will cause race conditions with parallel CI/CD test runners as multiple test workers will be checking the same inbox for verification codes.

2. Automated E2E Testing With Disposable Inboxes

Using disposable mailboxes means complete isolation. Each test runner generates an email address, then runs the app, registers, checks the email has been received, extracts the OTP/confirmation and verifies the email was successful.

// Automated End-to-End Test (Playwright / Node.js)

const { test, expect } = require('@playwright/test');

test('user onboarding email verification flow', async ({ page }) => {

  // 1. Dynamically provision a disposable inbox
  const inboxRes = await fetch('https://www.temp-mail.services/api/inbox/create', { method: 'POST' });
  const { address } = await inboxRes.json();

  // 2. Perform registration on staging application
  await page.goto('https://staging.myapp.com/signup');
  await page.fill('#emailInput', address);
  await page.fill('#passwordInput', 'SecureTesting123!');
  await page.click('#submitButton');

  // 3. Poll temporary inbox for confirmation email
  let messages = [];
  for (let attempt = 0; attempt < 10; attempt++) {
    await page.waitForTimeout(2000);
    const msgRes = await fetch(`https://www.temp-mail.services/api/inbox/${encodeURIComponent(address)}/messages`);
    const data = await msgRes.json();
    if (data.messages && data.messages.length > 0) {
      messages = data.messages;
      break;
    }
  }

  expect(messages.length).toBeGreaterThan(0);

  // 4. Retrieve message payload and parse 6-digit OTP code
  const messageId = messages[0].id;
  const detailRes = await fetch(`https://www.temp-mail.services/api/messages/${encodeURIComponent(messageId)}`);
  const { message } = await detailRes.json();
  const otpCode = message.text_body.match(/\b\d{6}\b/)[0];

  // 5. Submit OTP in application and verify dashboard access
  await page.fill('#otpInput', otpCode);
  await page.click('#verifyButton');
  await expect(page.locator('#dashboard')).toBeVisible();

});

3. Metrics To Test For

Alongside verifying emails have been received, you should also verify:

  • MTA Queue Latency: To help identify any bottlenecks in the outbound email queue, measure the difference between the time the email was sent and received.
  • Responsive HTML Templates: Ensure that the inline styling, dynamic variables and table layout are all working correctly with no broken tags or unescaped characters.
  • Headers: Validate that the critical email headers are present e.g Message ID, Date, List Unsubscribe, MIME Boundary dividers etc.

From a developers perspective, TempMail's homepage and 10 Minute Mail tool provide instant zero configuration mailboxes.

Browse more articles