# Transactional and promotional mail

Needs the Mailset CLI, signed in: step 1 of `mailset guide onboarding`.

Your product names each message's kind with `mode` in the `mailset` SDK, and Mailset checks that the message has what that kind needs. Replace example.com with your domain.

- `transactional`, the default: sign-in codes, receipts, alerts. It needs no unsubscribe, and Mailset refuses it if it carries `List-Unsubscribe` or `Precedence: bulk`: that's promotional mail under another name.
- `promotional`: newsletters, digests, offers. It goes to one address in `to`, with no `cc` or `bcc`. Mailset adds a one-click `List-Unsubscribe` and puts the link where you write `{{mailset_unsubscribe}}`, or on a last line of each part when you don't.

Once someone uses that link, Mailset skips later promotional mail from that mailbox to them and your hook hears `unsubscribed` (`mailset guide product-events`). With a domain key the opt-out belongs to the sending domain, so promotional mail from any address on it skips them. Transactional mail still reaches them, and so does promotional mail from your other mailboxes and domains.

To run unsubscribes yourself, pass your own `List-Unsubscribe: <https://...>` and `List-Unsubscribe-Post: List-Unsubscribe=One-Click` in `headers`, with the same URL in the text and the HTML. Mailset then adds nothing, and honoring each opt-out is up to you. Campaigns sent through a campaigns key always bring their own.

## Steps

1. Make a key for your product's own mail: `mailset keys create --send --mailbox hello@example.com --name "Example API"`. If example.com only sends through Mailset and its mail lives elsewhere, make the key for the domain instead, naming the addresses your product uses: `mailset keys create --send --domain example.com --from hello@example.com --name "Example API"`.
2. Send newsletters from a subdomain with a key of their own. Add it as sending-only, since nobody reads mail there (`mailset domains add news.example.com --sending`), put its records in DNS (`mailset domains apply news.example.com --sending`, or `mailset guide dns-by-hand`), and make its key: `mailset keys create --send --domain news.example.com --from news@news.example.com --name "Example announcements"`. Nobody has an address there, so `--any-address` in place of `--from` is fine too. Point `replyTo` at an inbox someone reads.
3. Keep each printed `MAILSET_KEY` in your secret store.
4. Install the SDK with `npm install mailset` and send. The docs have the rest: the SDK at https://mailset.app/docs/sdk, promotional mail and its unsubscribe at https://mailset.app/docs/recipes/unsubscribes, batches at https://mailset.app/docs/recipes/batches, `deliverBy` at https://mailset.app/docs/recipes/deadlines, `idempotencyKey` at https://mailset.app/docs/recipes/retries, and a language with no SDK at https://mailset.app/docs/authentication/http.

```ts
import { Mailset } from 'mailset';

// Reads MAILSET_KEY from the environment.
const mailset = new Mailset();

await mailset.send({
	from: 'Example <hello@example.com>',
	to: 'ana@example.org',
	subject: 'Your Example code',
	text: 'Your code is 123456.',
});
```

5. Call `await mailset.key.check()` when your server starts and once a day. A key unused for 90 days stops working.

## Check

A refused message throws `MailsetError` with a stable `code` and a sentence saying what's missing. `mailset delivery search --sender news.example.com` shows what went out, and `mailset unsubscribes list news.example.com` shows who unsubscribed.

## Watch out

- One key per kind of mail. Each key has its own brake, so a paused newsletter key never stops sign-in codes: `mailset guide brakes`. A domain key covers its own domain only, never a subdomain, so news.example.com gets its own.
- The subdomain matters too. A spam report stops mail to that person from the domain it was about, so a report on news.example.com never costs them a sign-in code from example.com.
- A sign-in code is useless an hour late. Give it `deliverBy: '10m'`, so a limit that would hold it longer refuses it at once, and one still waiting then is dropped: `mailset guide sending-limits`.
- Mailset doesn't send product mail to Apple's Hide My Email addresses or to temporary inboxes, or promotional mail to someone who unsubscribed from that mailbox or domain. It doesn't throw either: the receipt's `skipped` names each one with its `reason` (`private_relay`, `disposable` or `unsubscribed`), everyone else gets the mail, and the delivery log says `skipped`. Don't retry it. A skip never counts against the brake.
- An unsubscribe holds until that person asks you for your mail again. Then run `mailset unsubscribes remove news.example.com --address ana@example.org`, or name the mailbox for a mailbox key's mail.

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content