# Email Live Sending

> Mailtrap's email sending product: an app sends transactional and promotional email over a REST API or SMTP, from a verified sending domain.

## When to use it

Use it when the user's app or platform sends email to its users. Pick the stream by email type:

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

- Use the API for code that makes HTTP calls or uses an SDK, and SMTP for stacks that only take SMTP settings. One account, verified domain and API token cover both streams and both methods.
- If the email type isn't clear, ask. If the user only asks to set up email for their app, with no sign of promotions, use Transactional. Never send promotional email through Transactional. Sending the same email once to a list (even a welcome email) isn't triggered per recipient: ask which stream applies.
- For campaigns and contacts managed in Mailtrap, test email that isn't delivered, or receiving email, use another product (table at the end).

## How to use it

### Before you start

Find out the user's stack, sending domain and from address, email types, and whether they have an API token. 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 to run, and don't say you checked.
- **Confirm first:** before adding a domain, and right before each live send, unless the current request names the recipients and content. For a list you put together: show the count and a sample, and send one message per recipient (one batch item each). On Free (150 per day), stop if the list is longer; paid plans queue extra emails hourly instead. If the plan isn't known, ask.
- **Secrets:** never ask for a token in chat. The user sets `MAILTRAP_API_TOKEN`, and code reads it. If the user pastes one anyway, don't use it: suggest a reset under Settings → API Tokens, and continue with the env var.
- **User only:** sign up at `mailtrap.io/register/signup`, create the first API token (Settings → API Tokens), add the DNS records, and complete compliance checks if asked.

### Steps

Send every API call with `Authorization: Bearer $MAILTRAP_API_TOKEN` and a normal `User-Agent`.

1. **Check, then add the domain:** `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. No `www`; a subdomain is verified as its own domain.
2. **Wait for verification:** poll `GET https://mailtrap.io/api/domains/{id}` until `dns_verified` is `true` and `compliance_status` is `compliant`; DNS usually takes a few hours. If the status asks for company info, a questionnaire or card verification, stop polling: the user completes it in the dashboard. For other statuses, ask the docs.
3. **Send** from an address on the verified domain (confirm first, as in Rules):

   ```bash
   curl -X POST https://send.api.mailtrap.io/api/send \
     -H "Authorization: Bearer $MAILTRAP_API_TOKEN" -H "Content-Type: application/json" \
     -d '{"from":{"email":"hello@example.com","name":"Example App"},"to":[{"email":"user@example.org"}],"subject":"Welcome","text":"Thanks for signing up."}'
   ```

   ```javascript
   import { MailtrapClient } from "mailtrap"; // npm install mailtrap; add bulk: true for the Bulk Stream
   const client = new MailtrapClient({ token: process.env.MAILTRAP_API_TOKEN });
   await client.send({ from: { email: "hello@example.com" }, to: [{ email: "user@example.org" }], subject: "Welcome", text: "Thanks for signing up." });
   ```

   - **Batch:** up to 500 messages per call at `/api/batch` on the same host.
   - **SMTP:** port 587 with STARTTLS, username `api`, password the API token.
   - **Bulk:** send only to recipients who opted in, and put `<a href="__unsubscribe_url__">Unsubscribe</a>` in the HTML.
   - For SDKs, fields and framework setup, use the Email API, SMTP or Bulk page (table at the end).

### Check it worked

`200` with `{"success": true, "message_ids": [...]}`, and the message is listed in `GET https://mailtrap.io/api/email_logs`.

### If something fails

| Error                                             | Fix                                                                                                                                                                                                               |
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`, `403 Forbidden`               | Also returned for an unverified domain. In order: send from a domain that passed step 2; check `MAILTRAP_API_TOKEN` is set and sent as `Authorization: Bearer`; the user checks the token has Admin on the domain |
| `From: Header does not match the sender's domain` | Put `from` on the exact verified domain (Laravel: `MAIL_FROM_ADDRESS`)                                                                                                                                            |
| 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 from code over HTTP or an SDK, in detail                     | [email-api.md](https://mailtrap.io/email-api.md)                              |
| Configure Laravel, Nodemailer, WordPress or another SMTP stack    | [smtp-service.md](https://mailtrap.io/smtp-service.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)       |
| Receive email in an app                                           | Inbound Email: [inbound-email.md](https://mailtrap.io/inbound-email.md)       |
| Check current plans and prices                                    | [pricing.md](https://mailtrap.io/pricing.md)                                  |

## Documentation

- [Quickstart](https://docs.mailtrap.io/getting-started/email-api-smtp.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) · [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, 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.
