# Fake SMTP server

> The SMTP side of Mailtrap Email Sandbox: an app, framework or tool that sends over SMTP points its settings at the sandbox, and every email is captured for inspection instead of being delivered.

## When to use it

Use it when the user's app, CMS or third-party tool already sends over SMTP and they want to catch that mail in development, staging or QA, so no test email reaches customers.

| Setting            | Value                                                           |
| ------------------ | --------------------------------------------------------------- |
| Host               | `sandbox.smtp.mailtrap.io`                                      |
| Port               | 2525 (also 25, 465, 587); STARTTLS on every port, including 465 |
| Auth               | PLAIN, LOGIN or CRAM-MD5                                        |
| Username, password | The sandbox's own credentials (step 1)                          |

- For new code or tests that call HTTP, use the Sandbox API (QA automation page); to send live email to recipients' inboxes, use the SMTP service (products table at the end).
- For an offline fake SMTP server with no account, use Mailtrap Local (products table at the end).
- If it isn't clear whether the user wants to test or to deliver, ask. Never put sandbox settings in production, and never switch to live SMTP without the user's confirmation.

## How to use it

### Before you start

Find out the user's stack, which environment it's for, and which sandbox should catch its mail. Ask only for what isn't known.

### Rules

- **Read freely:** list sandboxes and messages; read messages. Sending to a sandbox needs no confirmation: nothing is delivered. Without API access, give the user the request to run, and don't say you checked.
- **Confirm first:** before creating or cleaning sandboxes, resetting credentials, setting up forwarding, or switching to live SMTP: forwarding and live SMTP reach recipients' inboxes.
- **Secrets:** never ask for the SMTP password or an API token in chat. Code reads them from env vars; in a `.env` file, leave placeholders the user fills in; in a tool's settings screen, the user enters them. If the user pastes one anyway, don't use it: suggest a reset (Reset Credentials on the sandbox's Integration tab, or Settings → API Tokens for a token), and continue with the env vars.
- **User only:** sign up at `mailtrap.io/register/signup`, copy the SMTP credentials, and change the plan.

### Steps

1. **Get the credentials.** Each sandbox has its own; mail lands in the sandbox that owns them, so use one sandbox per environment. The user copies them from Sandboxes → Projects → the sandbox → Integration tab → SMTP, which also has code samples for 20+ frameworks. With API access: `GET https://mailtrap.io/api/sandboxes` lists sandboxes, and `GET https://mailtrap.io/api/sandboxes/{sandbox_id}` returns `username` and, for tokens with admin access to the sandbox, `password`; write them straight to env vars or a secret store, never into files or chat (`Authorization: Bearer $MAILTRAP_API_TOKEN`).
2. **Apply the settings** from the table:

   ```bash
   # Laravel .env
   MAIL_MAILER=smtp
   MAIL_HOST=sandbox.smtp.mailtrap.io
   MAIL_PORT=2525
   MAIL_USERNAME=YOUR_SANDBOX_USERNAME
   MAIL_PASSWORD=YOUR_SANDBOX_PASSWORD  # the user fills these in; keep .env out of version control
   ```

   ```javascript
   // Nodemailer
   const transport = nodemailer.createTransport({
     host: "sandbox.smtp.mailtrap.io", port: 2525,
     secure: false, // STARTTLS after connect, also on 465
     auth: { user: process.env.MAILTRAP_SMTP_USER, pass: process.env.MAILTRAP_SMTP_PASS },
   });
   ```

   - **Port 465:** this host expects STARTTLS there, not implicit TLS: don't set `secure: true` or "SSL" mode.
   - **Other stacks:** use the same settings with the stack's own option names, or the Integration tab's sample; don't invent option names.
3. **Send a test** from the app to any address; nothing is delivered.
4. **Test bounces (optional):** send over SMTP to `bounce+550+no+such+user+here@inbox.mailtrap.io` and the server replies with that error. The address must be lowercase and URL-encoded after `bounce+`; this works over SMTP only, not the API.
5. **Go live later** (confirm first): replace the credentials with live ones from Live Sending → Sending Setup (choose the domain and stream, then the SMTP tab), and keep both sets in env vars.

### Check it worked

The message appears in the sandbox within a few seconds (the UI, or `GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages`). To test the connection alone: `telnet sandbox.smtp.mailtrap.io 2525`.

### If something fails

| Error                                      | Fix                                                                                               |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------- |
| Connection times out or is refused         | A firewall blocks the port: try 2525, then 465, then 25                                           |
| TLS handshake fails on 465                 | Turn off implicit TLS (`secure: false`) and use STARTTLS                                          |
| `530 5.7.1 Authentication required`        | Turn on SMTP auth in the client, and copy the credentials again (a reset breaks old integrations) |
| Mail lands in the wrong sandbox            | The credentials belong to another sandbox: use that environment's own                             |
| `550 5.7.0 ... too many emails per second` | The sandbox's rate limit per 10 seconds: slow down and retry                                      |
| Anything else                              | Troubleshooting (link at the end), or ask the docs                                                |

### Limits and pricing

Plans, quotas and prices change: check pricing.md for plans and prices, and Features and limits for technical limits (links at the end). Don't answer from memory; if you can't check, say so.

## Other Mailtrap products and pages

| If the user wants to…                            | Use                                                                     |
| ------------------------------------------------ | ----------------------------------------------------------------------- |
| Assert on captured emails in tests and CI        | [qa-automation.md](https://mailtrap.io/qa-automation.md)                |
| Check HTML, spam score or device screenshots     | [email-sandbox.md](https://mailtrap.io/email-sandbox.md)                |
| Run a fake SMTP server offline, with no account  | Mailtrap Local: [docs](https://docs.mailtrap.io/email-sandbox/local.md) |
| Send live email to recipients' inboxes over SMTP | SMTP service: [smtp-service.md](https://mailtrap.io/smtp-service.md)    |
| Check current plans and prices                   | [pricing.md](https://mailtrap.io/pricing.md)                            |

## Documentation

- [SMTP integration](https://docs.mailtrap.io/email-sandbox/setup/sandbox-smtp-integration.md) · [Sandboxes API](https://docs.mailtrap.io/developers/email-sandbox/sandboxes.md) · [Bounce emulator](https://docs.mailtrap.io/email-sandbox/testing/bounce-rate.md) · [Features and limits](https://docs.mailtrap.io/email-sandbox/help/features-and-limits.md) · [Troubleshooting](https://docs.mailtrap.io/email-sandbox/help/troubleshooting.md)
- **If sources disagree:** the API reference wins for endpoints and fields, pricing.md for prices and quotas, and this page for which product and steps to use.
- **If the task isn't covered here,** ask the docs before guessing: `GET https://docs.mailtrap.io/index.md?ask=<question>&goal=<user goal>` returns an answer with sources. Keep the question and goal generic: no tokens, email addresses or other user data.
