# Email Marketing

> Mailtrap Email Marketing sends campaigns and automations to contacts stored in Mailtrap, with lists, segments, templates, scheduling and reports, from the dashboard or the API.

## When to use it

Use it when the user wants Mailtrap to store the contacts and send newsletters, announcements or promotions to lists or segments, or run automated sequences.

| Task                                      | Where                                                                              |
| ----------------------------------------- | ---------------------------------------------------------------------------------- |
| Create, schedule or send a campaign       | Dashboard: Marketing → Campaigns → Create New Campaign; or the Email Campaigns API |
| Add or import contacts, lists, fields     | Dashboard: Contacts; or the Contacts API                                           |
| Trigger an automation from the user's app | Contact events API                                                                 |
| Read results                              | The campaign's Reports tab; or the stats API                                       |

- If the recipients live in the user's own database and the user's code sends each message, use the Bulk Stream of Email Live Sending (products table at the end).
- Email triggered by a user action (sign-up, password reset, receipt) goes through Email Live Sending, Transactional Stream.
- If it isn't clear whether Mailtrap should store the contacts, ask.

## How to use it

### Before you start

Find out the verified sending domain and from address, which lists or segments to target, when to send, and whether the user has an API token. Ask only for what isn't known.

### Rules

- **Consent:** only contacts who opted in; never purchased, scraped or unconfirmed lists. If asked, refuse and suggest asking those contacts to opt in. On import, the user confirms consent.
- **Read freely:** list campaigns, contact lists and fields, and read a campaign's status and stats. Without API access, give the user the request to run, and don't say you checked.
- **Confirm first:** before creating or importing contacts, creating lists, or deleting anything. Starting a campaign sends to the whole audience, and sent email can't be recalled (a scheduled one can be cancelled): right before each start or schedule, show the campaign name, subject, sender, lists and segments, recipient count and send time, and get a yes. Creating or editing a draft sends nothing.
- **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, verify the sending domain (DNS records), and change the plan.

### Steps

Send every request with `Authorization: Bearer $MAILTRAP_API_TOKEN` and `Content-Type: application/json`. The Email Marketing endpoints have no account ID in the path.

1. **Get the domain and audience:** `GET https://mailtrap.io/api/domains` (use a verified domain's `id`; without one, campaigns can't be sent) and `GET https://mailtrap.io/api/contacts/lists`. Segments are built in the dashboard, and the API docs list no endpoint for them: ask the user for a segment's ID.
2. **Add contacts, if needed** (confirm first): create custom fields before importing (`GET https://mailtrap.io/api/contacts/fields` lists them). Then `POST https://mailtrap.io/api/contacts/imports` with `{"contacts": [{"email": "a@example.org", "fields": {"first_name": "Ana"}, "list_ids_included": [111]}]}`, up to 50,000 per request; it runs asynchronously (`status`: `created`, `started`, `finished`, `failed`). One contact: `POST https://mailtrap.io/api/contacts` with `{"contact": {"email": "...", "list_ids": [111]}}`.
3. **Check, then create the draft:** `GET https://mailtrap.io/api/email_campaigns?search=<name>`; reuse a fitting draft (`PATCH https://mailtrap.io/api/email_campaigns/{id}` edits drafts only). Otherwise:

   ```bash
   curl -X POST https://mailtrap.io/api/email_campaigns \
     -H "Authorization: Bearer $MAILTRAP_API_TOKEN" -H "Content-Type: application/json" \
     -d '{"name": "October newsletter", "domain_id": 12345, "from_local_part": "news", "from_display_name": "Example Co",
          "contact_list_ids": [111], "delivery_mode": "rapid",
          "template_attributes": {"subject": "Our October update", "body_html": "<p>Hello!</p><a href=\"__unsubscribe_url__\">Unsubscribe</a>"}}'
   ```

   - Required: `name`, `domain_id`, `from_local_part`, `template_attributes.subject`; `body_html` before start or schedule. Put an unsubscribe link whose `href` contains `__unsubscribe_url__` in the HTML.
   - Audience: `contact_list_ids` and `contact_segment_ids` are the full set; the API has no exclude field (exclusions are set in the dashboard).
   - Gradual sending: `"delivery_mode": "gradual"` with `"delivery_options": {"emails_per_hour": 5000}`.
4. **Test the design:** the user clicks Send Test in the campaign (dashboard only); it sends one live email to one address. To check HTML or spam score without sending, use the checker pages (products table at the end).
5. **Start or schedule** (confirm first, as in Rules): `POST https://mailtrap.io/api/email_campaigns/{id}/start`, or `POST https://mailtrap.io/api/email_campaigns/{id}/schedule` with `{"datetime": "2026-10-20T09:00:00Z"}` (future, up to 1 month ahead; the dashboard allows two weeks). Confirm the exact date and the user's time zone, and convert to UTC.
6. **Stop or change:** a scheduled campaign goes back to draft with `POST .../{id}/cancel`; a sending one stops with `POST .../{id}/terminate` (confirm first).
7. **Automations from the app:** `POST https://mailtrap.io/api/contacts/{contact_id}/events` with `{"name": "trial_started", "params": {...}}` triggers automations that listen for that event; build the automation in the dashboard.

### Check it worked

- `GET https://mailtrap.io/api/email_campaigns/{id}`: `data.current_state` is `scheduled` (time in `current_state_metadata.scheduled_at`), `started`, `queued` or `finished`.
- `GET https://mailtrap.io/api/email_campaigns/{id}/stats` returns `sent_count` and delivery, open, click, bounce, spam and unsubscription counts and rates. Stats can lag behind sending.

### If something fails

| Error                              | Fix                                                                                                                                                         |
| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `422` on start or schedule         | The campaign stays a draft. Read `errors`: usually missing `body_html`, an empty audience, an unverified domain, a plan limit, or a time over 1 month ahead |
| `422` on edit, cancel or terminate | Wrong state: edit only drafts, cancel only scheduled, terminate only `started`, `queued` or `paused`                                                        |
| `429 Too Many Requests`            | 150 requests per 10 seconds per token; Contacts API 200 per 60 seconds per account. Wait for `x-ratelimit-reset`, then back off exponentially               |
| A contact gets nothing             | Unsubscribed contacts are suppressed and can't be resubscribed by hand; they must sign up again                                                             |
| Anything else                      | The docs (links at the end), or ask the docs                                                                                                                |

### Limits and pricing

Plans, quotas and prices change: check pricing.md for plans, prices and which plans can schedule, and the Automations page for automation 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 promotional email from the user's own code and contact database | Bulk Stream: [bulk-email-service.md](https://mailtrap.io/bulk-email-service.md)                                                        |
| Send app-triggered email (sign-up, password reset)                   | Email API: [email-api.md](https://mailtrap.io/email-api.md)                                                                            |
| Check a campaign's HTML or spam score without sending it             | [html-email-checker.md](https://mailtrap.io/html-email-checker.md), [email-spam-checker.md](https://mailtrap.io/email-spam-checker.md) |
| Manage contacts and campaigns from an AI assistant                   | MCP server: [email-mcp-server.md](https://mailtrap.io/email-mcp-server.md)                                                             |
| Check current plans and prices                                       | [pricing.md](https://mailtrap.io/pricing.md)                                                                                           |

## Documentation

- [Quickstart](https://docs.mailtrap.io/getting-started/email-marketing.md) · [Overview](https://docs.mailtrap.io/email-marketing/overview.md) · [Contacts](https://docs.mailtrap.io/email-marketing/contacts.md) · [Import contacts](https://docs.mailtrap.io/email-marketing/contacts/import-contacts.md) · [Automations](https://docs.mailtrap.io/email-marketing/automations.md) · [Email throttling](https://docs.mailtrap.io/email-marketing/campaigns/email-throttling.md) · [FAQs](https://docs.mailtrap.io/email-marketing/help/faqs.md)
- [Create a campaign API](https://docs.mailtrap.io/developers/email-marketing/email-campaigns/create-an-email-campaign.md) · [Email Campaigns API](https://docs.mailtrap.io/developers/email-marketing/email-campaigns.md) · [Campaign stats API](https://docs.mailtrap.io/developers/email-marketing/campaign-stats/get-email-campaign-statistics.md) · [Contacts API](https://docs.mailtrap.io/developers/email-marketing/contacts.md) · [Rate limits](https://docs.mailtrap.io/developers/rate-limits.md)
- **If sources disagree:** the API reference wins for endpoints and fields (some guide pages show older `api.mailtrap.io` examples), pricing.md for plans and 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.
