Skip to content
destroy.network is now dissolve.email
Tutorials

Testing Email Flows with Playwright and Temporary Inboxes

Automate your email verification tests with Playwright and temporary inboxes. Perfect for testing signups, password resets, and transactional emails.

By dissolve.email team

8 min read

Code editor showing Playwright test automation

Testing email flows in your application can be challenging. You need real email addresses that receive real emails, but you don't want to clutter personal inboxes or deal with flaky third-party email services.

This tutorial shows you how to use the dissolve.email API with Playwright to create robust, automated email tests.

Why Automate Email Testing?

Email is critical to most applications. User registration, password resets, notifications, and transactional emails all rely on it. Yet email testing is often skipped or done manually because it's perceived as difficult.

With proper automation, you can:

  • Catch email delivery issues before they reach production
  • Verify email content and formatting automatically
  • Test email-dependent user flows end-to-end
  • Run tests in CI/CD without manual intervention

Setting Up the Test Environment

First, let's set up a Playwright test file with the necessary dependencies:

// test/helpers/email.ts
import { test, expect } from '@playwright/test';

const API_URL = 'https://api.dissolve.email/api';

interface Inbox {
  id: string;
  address: string;
}

interface Message {
  id: string;
  subject: string;
  from: string;
  body: string;
}

async function createInbox(): Promise<Inbox> {
  const res = await fetch(`${API_URL}/inbox`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ domain: 'dissolve.email' }),
  });
  return res.json();
}

async function waitForEmail(
  inboxId: string,
  timeout = 30000
): Promise<Message> {
  const start = Date.now();
  while (Date.now() - start < timeout) {
    const res = await fetch(`${API_URL}/inbox/${inboxId}/messages`);
    const messages = await res.json();
    if (messages.length > 0) {
      return messages[0];
    }
    await new Promise(r => setTimeout(r, 1000));
  }
  throw new Error('Timeout waiting for email');
}

Testing User Registration

Here's a complete example testing a signup flow with email verification:

// test/registration.spec.ts
test('user registration with email verification', async ({ page }) => {
  // Create a temporary inbox for this test
  const inbox = await createInbox();

  // Navigate to signup page
  await page.goto('/signup');

  // Fill out registration form
  await page.fill('[name="email"]', inbox.address);
  await page.fill('[name="password"]', 'SecureP@ssw0rd!');
  await page.click('button[type="submit"]');

  // Wait for confirmation message
  await expect(page.locator('.success-message')).toBeVisible();

  // Wait for verification email
  const email = await waitForEmail(inbox.id);

  // Verify email subject
  expect(email.subject).toContain('Verify your email');

  // Extract verification link from email body
  const linkMatch = email.body.match(/href="([^"]+verify[^"]+)"/);
  expect(linkMatch).toBeTruthy();

  // Visit verification link
  await page.goto(linkMatch![1]);

  // Verify account is now active
  await expect(page.locator('.verified-message')).toBeVisible();
});

Testing Password Reset

Password reset flows are another common use case:

// test/password-reset.spec.ts
test('password reset flow', async ({ page }) => {
  const inbox = await createInbox();

  // Create user with this email first (setup)
  // ... your user creation logic

  await page.goto('/forgot-password');
  await page.fill('[name="email"]', inbox.address);
  await page.click('button[type="submit"]');

  // Wait for reset email
  const email = await waitForEmail(inbox.id);

  expect(email.subject).toContain('Reset your password');

  // Extract reset link and complete flow
  const resetLink = email.body.match(/href="([^"]+reset[^"]+)"/);
  await page.goto(resetLink![1]);

  await page.fill('[name="newPassword"]', 'NewSecureP@ss!');
  await page.fill('[name="confirmPassword"]', 'NewSecureP@ss!');
  await page.click('button[type="submit"]');

  await expect(page.locator('.password-updated')).toBeVisible();
});

CI/CD Integration

These tests run perfectly in CI/CD environments. No email server setup, no SMTP configuration, just HTTP requests to the dissolve.email API.

For high-volume testing, consider using an API key to increase rate limits and access additional features.

Best Practices

  • Create a new inbox for each test to ensure isolation
  • Use meaningful timeout values based on your email delivery speed
  • Clean up inboxes after tests or let them expire naturally
  • Parse emails carefully, since HTML content may vary
  • Consider using the API's webhook feature for real-time notifications

Next Steps

Ready to start automating your email tests? Check out our API documentation for the complete reference, and create your first test inbox to see it in action.

Try it while you read

A disposable inbox takes one press on the home page. No signup.

Generate an inbox