# Email Sandbox API for safe SMTP testing

Test email safely with MailSlurp. Capture outgoing mail without delivery, or receive your application's messages in private inboxes and verify links, codes, and content by API.

![An envelope with a protective shield and magnifying glass for safe email testing](https://www.mailslurp.com/_astro/email-sandbox-header-v1.eNjfUkTb_ZjwjPV.png)

An email sandbox lets you test signup confirmations, password resets, receipts, and alerts without filling customer inboxes with test mail. You need to see the message your application produced and, for an account flow, check what happens after the recipient uses it.

MailSlurp supports both parts: capture outgoing mail without delivering it, or receive the application's real messages at private test addresses and complete the signup, reset, or OTP journey.

For software QA, the sandbox is where you inspect messages produced by your own application. Keep that task distinct from a security system that opens suspicious attachments in an isolated environment. Here, the checks concern the application's recipient, content and account action.

## What is the best email sandbox for developers?

The best email sandbox for developers lets each test create its own private inbox, catch the email before it reaches a customer, wait for the message in code and use its link or code. MailSlurp does all of this through one API: an inbox can capture outgoing mail without delivering it, or receive your application's real email through its normal provider.

| Sandbox   | How mail gets in         | Read it in a test |
| --------- | ------------------------ | ----------------- |
| MailSlurp | Capture or real delivery | Wait methods      |
| Mailtrap  | SMTP capture             | REST API          |
| Mailpit   | Local SMTP capture       | Self-hosted API   |

- **MailSlurp:** a hosted API that creates a separate inbox for every test, with an expiry, so parallel runs never share messages. The same account adds real phone numbers for SMS codes, device previews and inbox placement tests.
- **Mailtrap:** a hosted SMTP sandbox for staging mail. Its free plan holds 50 test emails a month in one sandbox, without a sandbox email address.
- **Mailpit:** a free, open-source SMTP catcher you run on your own machine or server. It sees only the mail your application sends to it.

Mailtrap and Mailpit details are from their own websites in November 2026.

## When teams adopt an email sandbox

- They need to test signup, reset, or magic-link journeys safely.
- They need repeatable message checks in CI instead of manual inbox review.
- They need to inspect the recipient, subject, HTML, headers, and attachments when a test fails.
- They need parallel tests to keep their emails and account state separate.

## Sandbox architecture in practice

Choose the approach that answers your test's question:

- **Check an outgoing message without delivery.** Create a MailSlurp virtual inbox and send through that inbox's API or SMTP credentials. MailSlurp captures a sent-email record with `virtualSend: true`.
- **Check the application's sending and receiving journey.** Create a dedicated receiving inbox, give its address to the application, and trigger the real signup, reset, or notification flow. Wait for the incoming message, inspect it, and use its link or code.

The `virtualInbox` setting applies to messages sent **from** that MailSlurp inbox. Giving its address to a third-party sending service does not switch that service into no-send mode. For tests through your existing email provider, use controlled test recipients.

Before routing staging traffic through capture, trigger one message from the actual staging application to an address your team controls. Retrieve that send's record and confirm `virtualSend: true`. If the application still uses another provider or another inbox's SMTP credentials, changing a test's API setup will not change the application's sending route. Use the SMTP example below to check a client connection, then repeat capture with your staging application's sender. The API example checks a direct SDK send.

### Connect an SMTP application to the sandbox

For an application that already sends with SMTP, use the virtual inbox's SMTP credentials in its staging mail configuration. Keep the host, port, username and password together; changing the recipient address alone does not change the sending route. Send from the virtual inbox's address and read its **sent** records to inspect captured mail.

This Node.js example uses Nodemailer as the SMTP client. It creates its own virtual inbox, reads the secure SMTP connection details, sends one uniquely named message and polls for its captured record for up to 30 seconds. The recipient is a reserved example address, and the assertion checks `virtualSend` before treating capture as successful. Install `mailslurp-client` and `nodemailer`, set `MAILSLURP_API_KEY`, save the code as `smtp-sandbox.mjs`, and run `node smtp-sandbox.mjs`.

Show the complete SMTP capture example

```javascript
import assert from "node:assert/strict";
import { randomUUID } from "node:crypto";
import { setTimeout as delay } from "node:timers/promises";
import nodemailer from "nodemailer";
import { MailSlurp } from "mailslurp-client";

const apiKey = process.env.MAILSLURP_API_KEY;
if (!apiKey) throw new Error("Set MAILSLURP_API_KEY");
const mailslurp = new MailSlurp({ apiKey });
const inbox = await mailslurp.createInboxWithOptions({
  virtualInbox: true,
  expiresIn: 600_000,
});
try {
  const access = await mailslurp.getImapSmtpAccessDetails(inbox.id);
  const smtp = nodemailer.createTransport({
    host: access.secureSmtpServerHost,
    port: access.secureSmtpServerPort,
    secure: true,
    auth: {
      user: access.secureSmtpUsername,
      pass: access.secureSmtpPassword,
    },
    connectionTimeout: 15_000,
    socketTimeout: 30_000,
  });
  const recipient = "customer@example.test";
  const subject = `Sandbox check ${randomUUID()}`;
  const body = "Your staging receipt is ready.";
  const since = new Date();
  await smtp.sendMail({
    from: inbox.emailAddress, to: recipient, subject, text: body,
  });

  const deadline = Date.now() + 30_000;
  let captured;
  do {
    const page = await mailslurp.sentController.getSentEmails({
      inboxId: inbox.id, since, page: 0, size: 10,
    });
    const match = page.content?.find((email) => email.subject === subject);
    if (match) {
      captured = await mailslurp.sentController.getSentEmail({ id: match.id });
      break;
    }
    await delay(500);
  } while (Date.now() < deadline);

  assert.ok(captured, "SMTP accepted the message but no captured record appeared");
  assert.equal(captured.virtualSend, true, "Expected a no-delivery send");
  assert.equal(captured.inboxId, inbox.id);
  assert.ok(captured.to?.includes(recipient));
  assert.equal(captured.subject, subject);
  assert.equal(captured.body?.trim(), body);
  console.log("SMTP message captured and checked");
} finally {
  await mailslurp.inboxController.deleteInbox({ inboxId: inbox.id });
}
```

The polling window allows the SMTP send to appear in the API; it does not retry failed authentication or a rejected send. The first page is sufficient here because this new inbox sends one message. For a shared staging inbox, use a request-specific match and paginate its records instead of assuming the first ten contain your send. Keep SMTP credentials in your application's secret store, and never print the returned access object.

If SMTP authentication fails, check the returned credentials and secure port. If SMTP accepts the message but capture times out, inspect that inbox's sent records and the application's actual SMTP configuration. If the record reports `virtualSend: false`, stop treating that configuration as a sandbox and correct the sending inbox before routing staging traffic through it.

### Capture a send from a virtual inbox

Install `mailslurp-client` and set `MAILSLURP_API_KEY` in your environment. This TypeScript helper creates a virtual inbox, captures an example message, checks the sent record, and deletes only the inbox it created. Call `await checkCapturedEmail()` from your test.

```typescript
import assert from "node:assert/strict";
import { MailSlurp } from "mailslurp-client";

export async function checkCapturedEmail() {
  const apiKey = process.env.MAILSLURP_API_KEY;
  if (!apiKey) throw new Error("Set MAILSLURP_API_KEY");
  const mailslurp = new MailSlurp({ apiKey });
  const inbox = await mailslurp.createInboxWithOptions({
    virtualInbox: true,
    expiresIn: 600_000,
  });
  const recipient = "customer@example.test";

  try {
    const sent = await mailslurp.inboxController.sendEmailAndConfirm({
      inboxId: inbox.id,
      sendEmailOptions: {
        to: [recipient],
        subject: "Password reset requested",
        body: "This example is captured without external delivery.",
      },
    });
    const captured = await mailslurp.sentController.getSentEmail({ id: sent.id });
    assert.equal(captured.virtualSend, true);
    assert.equal(captured.inboxId, inbox.id);
    assert.ok(captured.to?.includes(recipient));
    assert.equal(captured.subject, "Password reset requested");
    assert.equal(captured.body, "This example is captured without external delivery.");
  } finally {
    await mailslurp.inboxController.deleteInbox({ inboxId: inbox.id });
  }
}
```

The helper rereads the stored sent-email record by ID and checks its virtual-send flag, sending inbox, recipient, subject and body. It does not wait for an incoming message: that belongs to the receiving workflow below. See the [virtual inbox documentation](https://www.mailslurp.com/docs/virtual-inbox/) for no-send setup.

## Receive your application's email through its normal provider

When the test needs to prove that an application's email arrives and works, keep its normal sending route and deliver to a private MailSlurp test address:

1. Create a separate receiving inbox for the test scenario.
2. Enter its address in the application's signup, reset, or notification flow.
3. Trigger the send through the application's configured SMTP server or email provider.
4. Use the [receive email API](https://www.mailslurp.com/email/receive-email-api/) to wait with an explicit timeout and match the expected sender, subject, or run-specific content.
5. Inspect the received message and follow its link or submit its code. Assert the resulting account state.
6. Delete the test's inbox during cleanup, including when an assertion fails.

For example, a password-reset test should open the delivered reset link, change the password, and confirm the expected account can sign in. The [complete receiving guide](https://www.mailslurp.com/guides/receive-emails/) covers inbox creation and message retrieval; [email integration testing](https://www.mailslurp.com/product/email-integration-testing/) connects those checks to the application journey.

Use [email webhooks](https://www.mailslurp.com/product/email-webhooks/) when incoming messages should start a parser or another background task. Keep the received message ID with a failed test result so you can inspect the message without copying private links or codes into shared logs.

Catch the email mistake before the customer does

Capture a staging message, inspect its content, and add the link or code check to your existing test suite with MailSlurp.

[Start email testing](https://app.mailslurp.com/sign-up/?onboardingRequest=testing)

![Separate envelopes representing isolated test inboxes](https://www.mailslurp.com/_astro/independent-inboxes-v3.Bx7bc8BG_1tDCOc.png)

## How do I use an email sandbox with Playwright?

Use Playwright for the browser journey and MailSlurp Email Sandbox for the message layer. Create a private inbox for the test, submit its address through the browser, wait for the expected email using a bounded subject or content match, extract the delivered link or OTP, and finish the journey in the same Playwright context.

For parallel CI, create one inbox per test scenario and delete it during teardown, including after a failure. Separate inboxes prevent concurrent scenarios from consuming one another's messages. The [Playwright email testing guide](https://www.mailslurp.com/blog/playwright-email-testing/) explains the pattern, the [complete Playwright fake-email example](https://www.mailslurp.com/examples/playwright-fake-email-test/) shows the implementation, and the [email testing API](https://www.mailslurp.com/product/email-testing-api/) provides the reusable inbox, wait, and message-inspection controls.

## How do I use an email sandbox with Cypress?

Use Cypress for the browser journey and MailSlurp Email Sandbox for the captured message. Install the official `cypress-mailslurp` plugin, create an inbox inside the test, submit its address in the app, and wait for the current run's subject, sender, or unique token before extracting the delivered link or OTP.

Give each test scenario its own inbox and delete it in `afterEach`, including after a failed assertion. That prevents cross-test message consumption and stale-email matches. The [Cypress email testing guide](https://www.mailslurp.com/blog/cypress-email-testing/) shows the pattern, the [complete Cypress plugin example](https://www.mailslurp.com/examples/cypress-test-email-plugin-js/) covers setup, and the [email testing API](https://www.mailslurp.com/product/email-testing-api/) provides the underlying inbox, wait, and inspection controls.

![An envelope with repeat arrows for repeatable email checks](https://www.mailslurp.com/_astro/repeat-email-check-v2.CoAbh6-P_ZhIgjB.png)

## What to verify before release

Choose assertions for the actual message. A password reset, invoice, and activity alert should not all pass the same generic "email received" check.

| Message                  | Useful checks after capture or receipt                                                                         |
| ------------------------ | -------------------------------------------------------------------------------------------------------------- |
| Signup or password reset | Correct account and recipient, expected link host, usable current token, and final verified or signed-in state |
| Email OTP                | Expected sender and message, exact code format including leading zeros, expiry and one-time-use policy         |
| Invoice or receipt       | Correct order details, currency and total, expected attachment type, and readable downloaded content           |
| Notification             | Correct recipient, required event details, and a link that opens the intended record                           |

Keep message-content checks separate from appearance. Use [device previews](https://www.mailslurp.com/product/device-previews/) for client-specific layout and dark-mode issues after the email's content and actions are correct.

For received messages, inspect the available authentication headers and investigate the sending domain with:

- [DMARC checker](https://www.mailslurp.com/tools/dmarc-checker/)
- [SPF checker](https://www.mailslurp.com/tools/spf-checker/)
- [DKIM checker](https://www.mailslurp.com/tools/dkim-checker/)
- [Email spam checker](https://www.mailslurp.com/tools/email-spam-checker/)

No-send capture checks the outgoing message. To measure inbox versus spam placement at mailbox providers, run a separate [inbox placement test](https://www.mailslurp.com/product/inbox-placement-deliverability-tests/).

## Local fake SMTP vs cloud sandbox

Local SMTP capture is useful when a developer needs to inspect the message produced by a local app. In shared staging or CI, decide who hosts the capture service, how workers isolate their mail, and how a failed test retrieves its message. MailSlurp supplies private inboxes, API access, and bounded waits for those shared test environments.

Changing SMTP settings changes the route under test. Keep a capture test for template and payload checks, then run a separate receiving test through your normal sending provider when you need to verify that route. A captured send is evidence about the outgoing message; the receiving test checks delivery to the test address and the customer action that follows.

Use the [SMTP tester](https://www.mailslurp.com/tools/smtp-tester/) for transport diagnostics, the [fake SMTP server guide](https://www.mailslurp.com/fake-smtp-server/) for safe capture setup, and this sandbox page when the workflow needs repeatable API assertions.

## Related implementation paths

- [Mail catch for staging and release review](https://www.mailslurp.com/product/mail-catch/)
- [Email integration testing](https://www.mailslurp.com/product/email-integration-testing/)
- [Email testing API](https://www.mailslurp.com/product/email-testing-api/)
- [Email testing product](https://www.mailslurp.com/product/email-testing/)
- [Disposable email API](https://www.mailslurp.com/product/disposable-email-api/)
- [Email webhooks](https://www.mailslurp.com/product/email-webhooks/)
- [Playwright email testing](https://www.mailslurp.com/blog/playwright-email-testing/)
- [Playwright email integration example](https://www.mailslurp.com/examples/playwright-fake-email-test/)
- [Cypress email testing](https://www.mailslurp.com/blog/cypress-email-testing/)
- [Cypress email plugin example](https://www.mailslurp.com/examples/cypress-test-email-plugin-js/)
- [SMS verification API](https://www.mailslurp.com/mobile/sms-verification-api/)
- [Email automation routing](https://www.mailslurp.com/product/email-automation-routing/)
- [Mailtrap alternative](https://www.mailslurp.com/mailtrap-alternative/)

## From sandbox capture to production-style operations

Teams often start with safe capture, then formalize ownership and event handling:

- [Messaging webhooks](https://www.mailslurp.com/product/email-webhooks/) for real-time downstream processing.
- [Team mailboxes](https://www.mailslurp.com/product/team-mailboxes/) for shared triage and accountability.
- [Email auto-reply](https://www.mailslurp.com/product/email-auto-reply/) for acknowledgement and escalation policies.

## FAQ

### Can I use Email Sandbox with any framework?

Yes. If your stack can call SMTP or HTTP APIs, you can use MailSlurp.

### Can Playwright read email from the sandbox?

Yes. Playwright drives the application while `mailslurp-client` creates the inbox, waits for the matching message, and returns its body, links, and metadata to the same test. No separate Playwright plugin is required.

### Can Cypress read email from the sandbox?

Yes. The official `cypress-mailslurp` plugin exposes the standard MailSlurp client through `cy.mailslurp()`, so the test can create an inbox, wait for a matching message, inspect its body or links, and delete the inbox during cleanup.

### Is this only for engineering teams?

QA, product, and support teams can inspect and validate messages in shared workspaces while engineering keeps the assertions in code.

### Does this replace production delivery infrastructure?

Email Sandbox focuses on safe testing and pre-release verification. Use it alongside production send systems when the team needs strong message evidence before anything customer-facing goes live.
