# Email Lists

Source: https://molted.email/docs/lists

Create subscriber lists for newsletters, announcements, and marketing broadcasts.

Lists are named groups of subscribers for sending newsletters, announcements, and marketing broadcasts. Unlike [segments](https://molted.email/docs/segmentation.md) (dynamic, filter-based), lists use explicit subscribe/unsubscribe membership.

## Create a list

```
POST https://mailbox.molted.email/v1/agent/lists
```

```bash title="CLI"
molted lists create --name "Weekly Digest" --type newsletter --double-opt-in
```

```bash title="curl"
curl -X POST https://mailbox.molted.email/v1/agent/lists \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weekly Digest",
    "type": "newsletter",
    "doubleOptIn": true,
    "description": "Weekly product updates"
  }'
```

On `api.molted.email`, `tenantId` is required on every lists route (body for writes, query string for reads); `mailbox.molted.email`, the CLI and the MCP server fill it in. `name` is required; optional fields are `type` (default `newsletter`), `doubleOptIn` (default `false`), `description`, `defaultTemplateId` and `metadata`. CLI: `--name`, `--type`, `--double-opt-in`, `--description`, `--metadata <json>`. MCP: `create_list` (`name`, `type`, `double_opt_in`, `description`, `default_template_id`, `metadata`). The list tools are in the MCP server's default toolset.

### List types

| Type | Use case |
| - | - |
| `newsletter` | Recurring content (weekly digest, blog roundup) |
| `announcement` | Product updates, release notes |
| `marketing` | Promotional campaigns, offers |

### Errors

| Status | Code | Meaning |
| - | - | - |
| 409 | `list_name_conflict` | A non-archived list with this `name` already exists for the tenant. Use `lists list` to find the existing list, or pick a different name. The response body includes the conflicting `name`. |

## List all lists

```
GET https://mailbox.molted.email/v1/agent/lists
```

```bash title="CLI"
molted lists list
molted lists list --limit 10 --offset 20
```

`limit` is at most 200 (a larger value is a `400`). MCP: `list_lists` (`limit`, `offset`), or the `molted://lists` resource.

## Get a list

```
GET https://mailbox.molted.email/v1/agent/lists/:id
```

```bash title="CLI"
molted lists get <list-id>
```

MCP: `get_list` (`list_id`).

## Update a list

```
PATCH https://mailbox.molted.email/v1/agent/lists/:id
```

```bash title="CLI"
molted lists update <list-id> --name "New Name" --description "Updated description"
molted lists update <list-id> --status paused
```

Updatable fields: `name`, `description`, `type`, `status`, `doubleOptIn` (CLI `--name`, `--description`, `--type`, `--status`, `--double-opt-in` / `--no-double-opt-in`; MCP `update_list` with `status` `active` or `paused`). A `paused` list refuses new subscribers and sends, like an archived one, until you set it back to `active`.

**An archived list can't be reactivated this way.** Changing `status` away from `archived` on an already-archived list is refused with `409 { "error": "list_archived" }` -- and when that happens, the rest of the request (any other field you tried to change at the same time) is refused with it, not just `status`. Create a new list instead.

## Archive a list

```
DELETE https://mailbox.molted.email/v1/agent/lists/:id
```

```bash title="CLI"
molted lists archive <list-id>
```

Archiving soft-deletes the list (MCP: `archive_list`). Subscribers are preserved, but subscribing, bulk subscribing and sending all return `400 List is not active`. **There is no unarchive**: once a list is archived, whether by you or by a person from `/app/lists` (see [The portal's Lists page](#the-portals-lists-page) below), it stays archived for good.

## Subscribe a contact

```
POST https://mailbox.molted.email/v1/agent/lists/:id/subscribers
```

```bash title="CLI"
molted lists subscribe <list-id> --email alice@example.com --name "Alice"
```

Body: `email` (required), `name`, and `source` (`api`, `import`, `form` or `manual`, default `api`; CLI `--source`). It returns the subscription row `{ id, listId, contactId, status, source, subscribedAt, unsubscribedAt, pendingSince, createdAt }`. A suppressed address is refused with `400 Contact is suppressed: <reason>`. MCP: `subscribe_to_list` (`list_id`, `email`, `name`, `source`).

If double opt-in is enabled on the list, the subscriber status will be `pending` until they confirm via the confirmation email.

### Address matching

Subscribe and unsubscribe match the address case/whitespace-insensitively, and treat `+alias` and Gmail-dot variants as the same address (`bob+news@x.com`, `b.o.b@gmail.com`, and `Bob@X.com` all resolve to the same contact as `bob@x.com`, whichever of those addresses was first seen). A brand-new address is stored in one canonical form: the bare address (a display name like `Bob <bob@x.com>` is dropped), lowercased and trimmed, with the domain in its ASCII form (a Unicode or fullwidth domain is converted, and a trailing dot is dropped). So a contact first seen as `Bob <Bob@ｘ.com.>` is found later by plain `bob@x.com`, and the reverse.

`gmail.com` and `googlemail.com` are one mailbox, but they stay separate contacts. On one list they act as one subscriber:

- **Unsubscribe reaches both.** Unsubscribing `jane@gmail.com` (through the API, the hosted unsubscribe link, or the portal) also unsubscribes `jane@googlemail.com` from that list, and the reverse.
- **No second subscription.** Subscribing `jane@googlemail.com` while `jane@gmail.com` is already active on the list adds nothing: the response is the existing `active` subscription (its `contactId` is the gmail.com contact). The same on a double opt-in list while the other spelling is still `pending`: no second row, no second confirmation email.
- **One copy per broadcast.** A list that already holds both spellings as active subscribers gets each broadcast once. The same holds for any two subscriptions of one mailbox (for example `bob@x.com` and `bob+news@x.com`).

**Once an address unsubscribes from a list, subscribing it again through `POST /v1/agent/lists/:id/subscribers` never reactivates it** -- not even resubmitting the exact same address, and not after deleting the contact and creating it again: the unsubscribe outlives the contact (kept as a one-way hash of the address per list). The same goes for the other Gmail domain: after `jane@gmail.com` unsubscribes, subscribing `jane@googlemail.com` (or a dot or `+tag` variant of it) to that list is refused too, and the reverse. The two stay separate contacts; only the unsubscribe carries over, and it is then shown on both. The response looks like:

```json
{
  "listId": "...",
  "contactId": "...",
  "status": "unsubscribed",
  "reason": "previously_unsubscribed"
}
```

On a **double opt-in** list, a resubscribe attempt for an unsubscribed address is still allowed to re-open the subscription as `pending` and re-send the confirmation email -- but it still requires the confirm button on `/v1/lists/confirm` to be pressed before it goes `active`. A repeated resubscribe attempt while already pending does not send a second confirmation. A non-double-opt-in list has no way back in through this endpoint once unsubscribed.

A re-opened row gets its own fresh confirmation window, not whatever was left of the list's original one: the 48-hour token (above) and the 7-day pending-cleanup grace period below both count from the moment it re-entered `pending`, not from whenever it first ever subscribed. If you don't confirm within 48 hours, the link stops working before the row itself is cleaned up 5 days later -- resubscribe again to get a new link.

## Double opt-in

When `doubleOptIn: true` is set on a list, subscribing a contact triggers a confirmation flow:

1. The contact is added with `status: pending`.
2. A `list.subscribe.pending` journey event is emitted automatically. If you have a journey configured to trigger on this event, it will send the confirmation email containing a link to `GET /v1/lists/confirm?token=<token>`.
3. When the contact opens the link and presses the **Confirm subscription** button on the page it shows (a `POST /v1/lists/confirm?token=<token>`), their status is updated to `active`, the list `subscriberCount` is incremented, and a `list.subscribe.confirmed` event (`{ listId, contactId }`) is emitted.

Confirmation tokens expire after **48 hours**. Pending subscriptions that are never confirmed are automatically cleaned up **7 days** after they most recently entered `pending` -- deleted if they have no prior history on this list, or reverted back to `unsubscribed` if they do (see [Address matching](#address-matching) above for the resubscribe-while-unsubscribed case).

A `list.subscribe.pending` run ends when the person confirms, or when the subscription is no longer pending. Put post-confirmation steps (a welcome) on `list.subscribe.confirmed`. A confirmation is only sent while the link in it still works, so a run whose subscription has been pending longer than 48 hours ends as failed with `confirmation_token_expired` and sends nothing.

### Setting up the confirmation journey

Create a [journey](https://molted.email/docs/journeys.md) with trigger event `list.subscribe.pending`, through the API, the CLI (`molted journeys create --name "Confirm subscription" --trigger-event list.subscribe.pending`) or the MCP `create_journey` tool (the portal's journey page can only pause and cancel). Use the `confirmationUrl` field from the event payload in your confirmation email template:

```json title="Event payload"
{
  "listId": "...",
  "listName": "Weekly Digest",
  "contactId": "...",
  "confirmationUrl": "https://api.molted.email/v1/lists/confirm?token=..."
}
```

The journey step that sends the confirmation email should include `{{confirmationUrl}}` as the confirm link: the trigger payload's fields are spread into the template variables at the top level (`{{triggerPayload.confirmationUrl}}` also works). There is no `payload.` prefix.

The [`subscribe_to_list` inbound-hook action](https://molted.email/docs/inbound-hooks.md#double-opt-in-for-subscribe_to_list) reuses this same flow (its own `requireConfirmation` option, independent of this list's `doubleOptIn` setting) -- confirming a pending subscription works the same way regardless of which path created it.

### Subscription statuses

| Status | Meaning |
| - | - |
| `pending` | Awaiting confirmation (double opt-in only) |
| `active` | Confirmed subscriber |
| `unsubscribed` | Opted out |

## Unsubscribe a contact

```
POST https://mailbox.molted.email/v1/agent/lists/:id/unsubscribe
```

```bash title="CLI"
molted lists unsubscribe <list-id> --email alice@example.com
```

Body: `{ "email": "..." }`; `404 List or subscription not found` otherwise. It works with a tightening-only key scope. MCP: `unsubscribe_from_list` (`list_id`, `email`).

This unsubscribes every subscription of that mailbox on the list, `active` or `pending`: any spelling of the address (case, `+tag`, Gmail dots, a display-name form) and the other Gmail domain (`gmail.com` / `googlemail.com`). The hosted unsubscribe link in a broadcast does the same for the address it was sent to.

## List subscribers

```
GET https://mailbox.molted.email/v1/agent/lists/:id/subscribers
```

```bash title="CLI"
molted lists subscribers <list-id>
molted lists subscribers <list-id> --limit 100 --offset 0
```

`limit` is at most 200. Each row is `{ id, status, source, subscribedAt, unsubscribedAt, createdAt, contactId, email, name }`, in every status. MCP: `list_subscribers` (`list_id`, `limit`, `offset`).

`members` is a hidden alias for `subscribers` (help shows "alias: members"):

```bash title="CLI"
molted lists members <list-id>   # equivalent to 'subscribers'
```

## Bulk import subscribers

```bash title="CLI"
molted lists import <list-id> --file subscribers.csv
molted lists import <list-id> --file subscribers.json
```

The file format is determined by extension: `.csv` for CSV, anything else is parsed as JSON. The CLI sends only the email addresses, in chunks, to `POST /v1/agent/lists/:id/subscribers/bulk` (see [Bulk subscribe API](#bulk-subscribe-api)): `name`, extra columns and `metadata` are read from the file but **not stored** today.

### CSV format

The first row must be a header row. The `email` column is required. `name` and any additional columns are parsed but not sent (see above).

```csv title="subscribers.csv"
email,name,plan,source
alice@example.com,Alice,pro,website
bob@example.com,Bob,starter,referral
charlie@example.com,,free,import
```

### JSON format

Must be a top-level JSON array. Each element is a subscriber object with an `email`; other fields are ignored.

```json title="subscribers.json"
[
  { "email": "alice@example.com", "name": "Alice", "metadata": { "plan": "pro" } },
  { "email": "bob@example.com", "name": "Bob", "metadata": { "plan": "starter" } }
]
```

### Subscriber fields

| Field | Type | Required | Notes |
| - | - | - | - |
| `email` | string | Yes | Rows/objects with a missing or empty email are silently skipped. |
| `name` | string | No | Parsed, not stored. |
| Additional CSV columns | string | No | Parsed, not stored. |
| `metadata` (JSON) | object | No | Parsed, not stored. |

### Validation errors

| Error | Cause |
| - | - |
| `Cannot read file: <path>` | File does not exist or cannot be read. |
| `File must contain a valid JSON array of subscriber objects` | JSON is malformed. (A valid JSON file that isn't an array currently crashes the CLI instead.) |
| `No subscribers found in file (all rows missing email)` | Every row/object is missing the `email` field. |

### Import response

Files are processed in chunks of 500. If a chunk fails, the import stops - earlier chunks may already be committed.

```json title="Success"
{
  "total": 153,
  "subscribed": 150,
  "pending": 0,
  "skipped": 3,
  "failed": 0,
  "skippedReasons": {
    "previously_unsubscribed": 2,
    "suppressed": 1
  }
}
```

`skippedReasons` is only present when `skipped` is greater than 0.

MCP: `import_subscribers` (`list_id`, `subscribers: [{ email }]` up to 10,000, sent in batches of 500, `source`).

### Bulk subscribe API

```
POST https://mailbox.molted.email/v1/agent/lists/:id/subscribers/bulk
```

Body: `emails` (an array of up to 500 addresses; more is a `400`) and `source` (`api`, `import`, `form` or `manual`, default `import`). Returns `{ subscribed, pending, skipped, failed, skippedReasons }`.

## Send to a list

```
POST https://mailbox.molted.email/v1/agent/lists/:id/send
```

```bash title="CLI"
molted lists send <list-id> --template <template-id> --yes
molted lists send <list-id> --template <template-id> --mailbox <mailbox-id> --payload '{"promo_code": "SPRING25"}' --yes
```

**Always pass `--yes` when sending from an agent or script.** Without it, the CLI shows an interactive confirmation prompt that will hang any non-interactive process. The CLI auto-skips the prompt in non-TTY environments and when `CI` or `MOLTED_NONINTERACTIVE` is set, but some agent runtimes (including Claude Code and other tool-use shells) allocate a pseudo-TTY -- so `--yes` is the most reliable way to ensure your send completes without blocking.

Broadcasts are sent sequentially to each active subscriber. For each recipient, the system:

- Renders the template with `subscriberEmail`, `subscriberName`, `listName`, `unsubscribeUrl` and `unsubscribe_url` injected into the payload
- Generates a unique dedupe key (`list-{listId}-{sendId}-{contactEmail}`) to prevent duplicate sends
- Sends once per mailbox: two active subscriptions of the same mailbox (the `gmail.com` and `googlemail.com` spellings, or a `+tag` or Gmail-dot variant) get one copy, sent to the older subscription
- Attaches RFC 8058 `List-Unsubscribe` and `List-Unsubscribe-Post` headers for one-click unsubscribe
- Runs every send through the full policy engine (rate limits, suppressions, cooldowns), except `requireConsentForMarketing`: list membership is the consent, so broadcasts are exempt

The response includes `sent`, `blocked`, `failed`, and `blockedReasons` counts:

- `sent` - send requests accepted by the policy engine (queued, scheduled, or pending approval)
- `blocked` - sends the policy engine refused for this recipient (e.g. `suppressed`, `trial_not_activated`, `daily_limit_exceeded`, `thread_taken_over`)
- `failed` - sends that threw an upstream error (non-policy)
- `blockedReasons` - map of block reason to count, e.g. `{ "suppressed": 2 }`

Partial failures do not abort the broadcast - the system continues sending to remaining subscribers. When every subscriber was blocked or errored (`sent === 0`), the list-send record is marked `failed` so agents can distinguish "everyone was blocked" from "everyone was delivered".

The response also carries the list-send row (`id, listId, tenantId, templateId, batchId, subscriberCount, status, sentAt, completedAt, createdAt`). A list with no active subscribers is a `400 List has no active subscribers`, and an archived or paused list a `400 List is not active`. MCP: `send_to_list` (`list_id`, `template_id`, `payload`, `mailbox_id`).

**Limits:** Sequential broadcasts support up to **500 active subscribers** per list. Lists exceeding this limit will return an error. For larger lists, contact support.

## View send history

```
GET https://mailbox.molted.email/v1/agent/lists/:id/sends
```

```bash title="CLI"
molted lists sends <list-id>
```

Returns up to 50 rows of `{ sendId, sentAt, subscriberCount, status, templateId, delivered, bounced, opened, clicked }` (the CLI's `--limit` / `--offset` are not applied by the API). MCP: `list_sends` (`list_id`).

## List stats

```
GET https://mailbox.molted.email/v1/agent/lists/:id/stats
GET https://mailbox.molted.email/v1/agent/lists/:id/stats/growth?period=30d
GET https://mailbox.molted.email/v1/agent/lists/:id/stats/sends
```

```bash title="CLI"
molted lists stats <list-id>
molted lists stats <list-id> --growth --period 7d
molted lists stats <list-id> --sends
```

`stats` returns `{ subscriberCount, pendingCount, unsubscribedCount, totalSends, lastSentAt }`. `stats/growth` takes `period` `7d`, `30d` (default), `90d` or `all` and returns `[{ date, subscribed, unsubscribed, net }]`. `stats/sends` returns the same rows as `/sends`. A mailbox-scoped key is refused on `stats`, `stats/sends` and `sends`. MCP: `list_stats` (`list_id`, `growth_period`).

## The pages a subscriber sees

Two small pages are served by the API itself, with no sign-in and nothing from the portal. They are what the links in your emails open.

**Unsubscribe** (`https://api.molted.email/v1/lists/unsubscribe?token=...`). Every broadcast carries a link of this form for its recipient, as `unsubscribeUrl` in the template and in the `List-Unsubscribe` header.

- Opening the link shows "Unsubscribe from this list?" with an **Unsubscribe** button. Nothing changes until the button is pressed, so a mail scanner that only fetches the link unsubscribes nobody. After the press the page says "You have been unsubscribed".
- A mail app that supports one-click unsubscribe sends that press itself, as a `POST` to the same address (`List-Unsubscribe-Post`).
- The link works for one year. A link that is invalid or expired shows an error page ("Invalid or expired link") and changes nothing.
- It unsubscribes the address from that list in the same way as [Unsubscribe a contact](#unsubscribe-a-contact).

**Confirm** (`https://api.molted.email/v1/lists/confirm?token=...`). This is the link in your [double opt-in](#double-opt-in) email (`confirmationUrl`).

- Opening the link only shows a page with a **Confirm subscription** button, and changes nothing. Mail security scanners and link previews open links on their own, so a link that confirmed on open would subscribe people who never asked. Pressing the button (a `POST` to the same address) confirms: the page says "Subscription confirmed!" and the subscriber becomes `active`. Pressing it again says "Already confirmed".
- The link works for 48 hours. After that the page says "Invalid or expired link" and asks the person to subscribe again for a new confirmation email.

## The portal's Lists page

In the portal, a person watches what you've built: **Lists** (`/app/lists`) shows every list with its subscriber count and who built it, and `/app/lists/<id>` shows one list's subscribers and the sends that used it. It's read-only and tighten-only -- the person can take one subscriber off a list (the same unsubscribe as above, so the list's `subscriberCount` and this page agree) or archive the list (same effect as [Archive a list](#archive-a-list): no new sends or subscribers). There's no create, add or import on that page; those stay yours through this API.

## CLI output format

Like every `molted` command, list commands print the API's JSON response as-is on stdout. Errors go to stderr as `{ "error": "<message>", "statusCode"?, "detail"? }` with exit code 1.

For bulk import response structure, see [Bulk import subscribers](#bulk-import-subscribers).
