# Bulk Email Service

> The Bulk Stream of Mailtrap Email Live Sending: an app or platform sends newsletters, promotions and other marketing email to its own recipient lists over the API or SMTP.

## When to use it

Use it when the user's own code or platform sends promotional email to recipients it stores itself (a database, a CRM, an app's user list). Mailtrap requires the Bulk Stream for all marketing email.

| Method                  | Bulk host                                     |
| ----------------------- | --------------------------------------------- |
| API, one message        | `POST https://bulk.api.mailtrap.io/api/send`  |
| API, up to 500 messages | `POST https://bulk.api.mailtrap.io/api/batch` |
| SMTP                    | `bulk.smtp.mailtrap.io`                       |

- Everything else matches the Transactional Stream: same token, request format and SMTP username. Only the host changes; SDKs also need their Bulk switch (Email API page).
- If the user wants Mailtrap to store the contacts and build, schedule and report on campaigns, use Email Marketing (table at the end).
- Email triggered by a user action (sign-up, password reset, receipt) goes through the Transactional Stream (`send.api.mailtrap.io`, `live.smtp.mailtrap.io`; Email API page).

## How to use it

### Before you start

Find out the user's stack, sending domain, where the list lives and how recipients opted in, the expected volume, and whether they have an API token. Ask only for what isn't known.

### Rules

- **Consent:** never send to purchased, scraped or unconfirmed lists; if asked, refuse and suggest asking those contacts to opt in. The user confirms that every recipient opted in.
- **Read freely:** list and check domains, webhooks (`GET https://mailtrap.io/api/webhooks`) and suppressions, 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 or webhook. Before any send, show the count, a sample of addresses, the subject and the send time, and get a yes, unless the current request names that exact list: listed addresses count; "the whole list" or "everyone" doesn't. The API doesn't report the remaining quota: ask the user, and stop if the send would exceed it (Free: 150 per day).
- **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, create the first API token, 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": "news.example.com"}}`, and give the user every record in `dns_records`. A separate subdomain for bulk email is recommended. Wait until `GET https://mailtrap.io/api/domains/{id}` shows `dns_verified: true` and `compliance_status: compliant`; for other statuses, see the Email API page or ask the docs.
2. **Add an unsubscribe link:** `<a href="__unsubscribe_url__">Unsubscribe</a>` in the HTML; without it, Mailtrap adds a footer link.
3. **Send in batches** (confirm first, as in Rules), one message per recipient, up to 500 per call; larger lists take several calls. `from` must be on the verified domain.

   ```bash
   curl -X POST https://bulk.api.mailtrap.io/api/batch \
     -H "Authorization: Bearer $MAILTRAP_API_TOKEN" -H "Content-Type: application/json" \
     -d '{"base": {"from": {"email": "news@news.example.com", "name": "Example"}, "subject": "October update", "html": "<p>What is new.</p><a href=\"__unsubscribe_url__\">Unsubscribe</a>", "category": "newsletter"},
          "requests": [{"to": [{"email": "a@example.org"}]}, {"to": [{"email": "b@example.org"}]}]}'
   ```

   - The API sends at once; schedule in the user's code.
   - SMTP: `bulk.smtp.mailtrap.io`, port 587 with STARTTLS, username `api`, password the API token.
   - Increase volume gradually, and keep spam complaints below 0.3%.
4. **Sync opt-outs back to the user's list** (check existing webhooks first, then confirm): `POST https://mailtrap.io/api/webhooks` with `{"webhook": {"url": "<user's endpoint>", "webhook_type": "email_sending", "sending_stream": "bulk", "event_types": ["unsubscribe", "spam_complaint", "bounce"]}}`.
   - The handler matches the payload event names `unsubscribe`, `spam` and `bounce` (`spam_complaint` is only the subscription name) and marks those addresses unsubscribed.
   - It verifies the `Mailtrap-Signature` header (hex HMAC-SHA256 of the raw body with the webhook's signing secret) and returns `200` within 30 seconds.
   - Mailtrap already blocks unsubscribed, bounced and complaining addresses on its own suppression list.

### Check it worked

- `/api/batch` returns `200` even if some messages fail: check `success` and `errors` on each item in `responses`.
- `GET https://mailtrap.io/api/email_logs` lists sent messages.

### If something fails

| Error                               | Fix                                                                                                                                                                                                               |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`, `403 Forbidden` | Also returned for an unverified domain. In order: send from a domain that passed step 1; check `MAILTRAP_API_TOKEN` is set and sent as `Authorization: Bearer`; the user checks the token has Admin on the domain |
| `429 Too Many Requests`             | Over 150 requests per 10 seconds per token: back off exponentially, send fewer, larger batches                                                                                                                    |
| A recipient never receives email    | Check `GET https://mailtrap.io/api/suppressions?email=<address>`. Don't reactivate an address that unsubscribed or complained unless the recipient asks                                                           |
| 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                                                                           |
| ------------------------------------------------------ | ----------------------------------------------------------------------------- |
| Build campaigns and manage contacts in Mailtrap        | Email Marketing: [email-marketing.md](https://mailtrap.io/email-marketing.md) |
| Send app-generated email, or see SDK and field details | Email API: [email-api.md](https://mailtrap.io/email-api.md)                   |
| Configure an SMTP-based stack                          | SMTP: [smtp-service.md](https://mailtrap.io/smtp-service.md)                  |
| Check spam score before a send                         | [email-spam-checker.md](https://mailtrap.io/email-spam-checker.md)            |
| Check current plans and prices                         | [pricing.md](https://mailtrap.io/pricing.md)                                  |

## Documentation

- [Bulk Stream](https://docs.mailtrap.io/email-api-smtp/setup/bulk-stream.md) · [Bulk batch API](https://docs.mailtrap.io/developers/email-sending/bulk/batch-send-emails.md) · [Domain setup](https://docs.mailtrap.io/email-api-smtp/setup/sending-domain.md) · [Webhooks](https://docs.mailtrap.io/email-api-smtp/advanced/webhooks.md) · [Suppressions list](https://docs.mailtrap.io/email-api-smtp/deliverability/suppressions-list.md)
- [Unsubscribe settings](https://docs.mailtrap.io/email-api-smtp/advanced/unsubscribe-settings-footers-and-links.md) · [Dedicated IP](https://docs.mailtrap.io/email-api-smtp/deliverability/ip-warmup.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.
