# SMTP service

> The SMTP relay of Mailtrap Email Live Sending: apps, frameworks and platforms that already send over SMTP switch to Mailtrap's host and credentials, from a verified sending domain.

## When to use it

Use it when the user's stack sends through an SMTP library, plugin or relay setting (Laravel Mail, Nodemailer, Django, Rails, a WordPress SMTP plugin, Supabase Auth, a mail server). Pick the host by email type:

| Email type                                                                                                          | Stream        | SMTP host               |
| ------------------------------------------------------------------------------------------------------------------- | ------------- | ----------------------- |
| Triggered by a user action or event: sign-up, password reset, receipt, alert                                        | Transactional | `live.smtp.mailtrap.io` |
| Newsletters, promotions, any marketing email from the user's own app or platform (Mailtrap requires Bulk for these) | Bulk          | `bulk.smtp.mailtrap.io` |

- For new code that can make HTTP calls, the Email API is an option too (table at the end).
- If the email type isn't clear, ask. With no sign of promotions, use Transactional. Never send promotional email through the Transactional host.

## How to use it

### Before you start

Find out the user's stack or platform, sending domain, email types, and whether they have SMTP credentials. Ask only for what isn't known.

### Rules

- **Read freely:** list and check domains, read Email Logs. Without API access, give the user the request or dashboard path, and don't say you checked.
- **Confirm first:** before adding a domain, changing a server-wide mail config or restarting a mail server, and right before each live send, unless the current request names the recipients and content.
- **Secrets:** never ask for the SMTP password (an API token) in chat. In code, read it from an env var such as `MAILTRAP_API_TOKEN`; in a `.env` file, leave a placeholder the user fills in; in a platform's settings screen, the user enters it. If the user pastes one anyway, don't use it: suggest a reset under Settings → API Tokens, and continue with the env var or placeholder.
- **Never send to purchased, scraped or unconfirmed lists;** if asked, refuse and suggest asking those contacts to opt in.
- **User only:** sign up at `mailtrap.io/register/signup`, copy the SMTP credentials, enter them in platform settings screens, add the DNS records, and complete compliance checks if asked.

### Steps

1. **Check, then add the domain.** With API access (`Authorization: Bearer $MAILTRAP_API_TOKEN`): `GET https://mailtrap.io/api/domains`; if the domain is missing, confirm, then `POST https://mailtrap.io/api/domains` with `{"domain": {"domain_name": "example.com"}}`, and give the user every record in `dns_records` exactly as returned. Without API access, the user adds it under Domains.
2. **Wait for verification:** poll `GET https://mailtrap.io/api/domains/{id}` until `dns_verified` is `true` and `compliance_status` is `compliant` (or the user checks for the Verified badge under Domains); DNS usually takes a few hours. If the status asks for company info, a questionnaire or card verification, the user completes it in the dashboard. For other statuses, ask the docs.
3. **Get the credentials (user):** Live Sending → Sending Setup → the domain → Transactional or Bulk → SMTP tab. Copy the exact values shown.

   | Setting  | Value                                                                             |
   | -------- | --------------------------------------------------------------------------------- |
   | Host     | `live.smtp.mailtrap.io` (Transactional) or `bulk.smtp.mailtrap.io` (Bulk)         |
   | Port     | 587 with STARTTLS; if blocked, 2525 with STARTTLS; Bulk also takes 465 with SSL   |
   | Username | `api`                                                                             |
   | Password | An API token with Admin on the sending domain; the same token works on both hosts |

4. **Apply the settings.** The `From:` header and the envelope from must both be on the verified domain. If the app sends both email types, use two SMTP connections, one per host.

   ```bash
   # Laravel .env
   MAIL_MAILER=smtp
   MAIL_HOST=live.smtp.mailtrap.io
   MAIL_PORT=587
   MAIL_USERNAME=api
   MAIL_PASSWORD=YOUR_API_TOKEN  # the user sets it on the server; keep .env out of version control
   MAIL_FROM_ADDRESS=noreply@example.com
   ```

   ```javascript
   // Nodemailer
   const transport = nodemailer.createTransport({
     host: "live.smtp.mailtrap.io", port: 587,
     auth: { user: "api", pass: process.env.MAILTRAP_API_TOKEN },
   });
   ```

   - **WordPress:** the user enters the settings in an SMTP plugin such as WP Mail SMTP (mailer Other SMTP, encryption TLS, authentication on).
   - **Other frameworks and platforms** (Django, Rails, Supabase and others): use the settings above with the stack's own option names, or its Mailtrap guide; don't invent option names.
   - **cPanel/Exim:** follow the cPanel guide (link at the end). These changes route all the server's mail and need root: back up the config, and confirm before editing it or restarting the server. Every From domain on the server must be verified. If marketing mail passes through the server, ask the user first: the guide routes everything to the Transactional host.
   - **Bulk:** put `<a href="__unsubscribe_url__">Unsubscribe</a>` in the HTML.
5. **Send one test** to an address the user controls (confirm first, as in Rules).

### Check it worked

The server accepts the message, it arrives, and it appears in Email Logs (dashboard, or `GET https://mailtrap.io/api/email_logs`).

### If something fails

| Error                                             | Fix                                                                                                                                                                                         |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`, or a `535` not listed below   | Also returned for an unverified domain. Finish step 2 and send from that domain; copy the username and password again from Sending Setup; the user checks the token has Admin on the domain |
| `From: Header does not match the sender's domain` | Put the header and envelope from on the exact verified domain (Laravel: `MAIL_FROM_ADDRESS`)                                                                                                |
| Connection times out or is refused                | Try the next port in step 3; if all fail, the user asks their host to allow outbound SMTP                                                                                                   |
| `535 5.7.8 Too many connections per account`      | The cap is 10 concurrent connections per account and per IP, across both hosts: limit the pool across all servers and workers (Nodemailer: `pool: true, maxConnections: 10`)                |
| 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 Sending 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                                                                           |
| ----------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| Send over HTTP with an official SDK, batches or templates         | Email API: [email-api.md](https://mailtrap.io/email-api.md)                   |
| Send promotional email from code, in detail                       | [bulk-email-service.md](https://mailtrap.io/bulk-email-service.md)            |
| Build campaigns and manage contacts in Mailtrap                   | Email Marketing: [email-marketing.md](https://mailtrap.io/email-marketing.md) |
| Test emails in development, staging or CI without delivering them | Email Sandbox: [email-sandbox.md](https://mailtrap.io/email-sandbox.md)       |
| Check current plans and prices                                    | [pricing.md](https://mailtrap.io/pricing.md)                                  |

## Documentation

- [SMTP integration](https://docs.mailtrap.io/email-api-smtp/setup/smtp-integration.md) · [Domain setup](https://docs.mailtrap.io/email-api-smtp/setup/sending-domain.md) · [API tokens](https://docs.mailtrap.io/email-api-smtp/setup/api-tokens.md) · [Domains API](https://docs.mailtrap.io/developers/email-sending/domains/list-domains.md)
- [Supabase](https://docs.mailtrap.io/guides/integrations/supabase/transactional-emails.md) · [cPanel](https://docs.mailtrap.io/guides/integrations/cpanel.md) · [Sending limits](https://docs.mailtrap.io/email-api-smtp/setup/sending-limits.md) · [Troubleshooting](https://docs.mailtrap.io/email-api-smtp/help/troubleshooting.md)
- **If sources disagree:** the API reference wins for endpoints and fields, Sending limits for quotas, pricing.md for prices, 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.
