MailSlurp logo

developers

Email Testing API for Developers

Automate inbox creation, email assertions, and end-to-end workflow checks using the MailSlurp email testing API.

For engineering teams, email failures are usually discovered too late: after a release, after user complaints, or during incident review. An email testing API moves those checks into automated pipelines.

MailSlurp provides API-first inbox control so you can create addresses on demand, receive messages, and assert email behavior in code. Start with the canonical email testing API product workflow when choosing the capability; use this page as the compact developer implementation reference.

What an email testing API should enable

  • Dynamic inbox creation for isolated test runs
  • Programmatic waiting for inbound email events
  • Content assertions on subject, body, links, and attachments
  • Framework-friendly integration for CI/CD

Minimal workflow example

import { MailSlurp } from "mailslurp-client";

const mailslurp = new MailSlurp({ apiKey: process.env.MAILSLURP_API_KEY! });

// 1. Create a unique inbox for this test run
const inbox = await mailslurp.createInbox();

// 2. Trigger your app flow that sends email to inbox.emailAddress

// 3. Wait for this test's message, with a bounded rule
const email = await mailslurp.waitController.waitForMatchingFirstEmail({
  inboxId: inbox.id!,
  timeout: 30_000,
  unreadOnly: true,
  matchOptions: {
    matches: [{ field: "SUBJECT", should: "CONTAIN", value: "Verify" }],
  },
});

// 4. Assert core behavior
if (!email.subject?.includes("Verify")) throw new Error("Expected verification subject");
if (!email.body?.includes("https://")) throw new Error("Expected link in email body");

This pattern is portable across signup, password reset, invite, and notification flows.

Use the email testing API with Playwright

Install @playwright/test and mailslurp-client, create one inbox per test, enter its address in the browser flow, and wait for the matching delivered email through the API. Then extract its link or OTP and continue in the same Playwright context. No separate MailSlurp Playwright plugin is required.

Use the Playwright email testing guide for the direct workflow, the complete Playwright implementation for runnable code, and Email Sandbox with Playwright when the application sends staging traffic through SMTP.

CI integration model

Use email assertions as release gates:

  1. Provision inbox per test execution.
  2. Trigger email-producing user journey.
  3. Assert message shape and business logic.
  4. Fail pipeline on missing or malformed email.

That prevents "works locally, fails in prod" email regressions.

High-value test scenarios

Account verification

Assert tokenized links, expiry behavior, and successful confirmation redirect.

Password reset

Validate one-time token flow and ensure previous tokens are invalidated where required.

Billing and compliance notifications

Confirm required content blocks and recipient routing in transactional pipelines.

Multi-tenant platforms

Isolate inboxes per tenant to verify routing and data boundaries.

Pair API checks with deliverability diagnostics

For production reliability, combine API assertions with:

This catches both workflow regressions and sender-health degradation.

Final takeaway

An email testing API should make email behavior testable like any other system contract. MailSlurp gives developers deterministic inbox control so email workflows can be verified continuously, not manually.