# Events for your product's mail

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

Mailset can post what became of each message your product sends with a `MAILSET_KEY` to one webhook on your server, so you hear when a receipt bounces or a sign-in code expires. Replace example.com with your domain.

## What you get

One event per recipient, in signed batches of up to 100: `{ "events": [...] }`.

- `queued`: a limit holds it. `sendsAt` says when it should go out and `reason` says why.
- `sent`: the provider took it.
- `delivered`: the recipient's server took it.
- `bounced`: it came back. `bounce.kind` is `hard` or `soft`, and `bounce.class` says what it means for the address: `mailbox` and `domain` mean it can't get mail.
- `complained`: the recipient marked it as spam. Stop writing to them.
- `failed`: Mailset couldn't send it. The provider refused it, its app key was paused, or five tries failed.
- `expired`: its `deliverBy` came while it waited, so it never went.
- `unsubscribed`: the recipient used Mailset's unsubscribe link in your promotional mail. Mailset skips that mailbox's promotional mail to them from now on, so take them off your list too.

Each carries `id`, `type`, `at` (ms), `message` (the `id` that `send` answered), `messageId` (the Message-ID header), `recipient` and `app` (the key's name). Never a subject or anything from the body. On `unsubscribed`, `message` and `messageId` name the mail whose link they used. `mailset hooks test` sends a `test` event, which is about no message.

## Steps

1. Pick an https URL on your server, on port 443, under a public host name such as hooks.example.com. Mailset refuses IP addresses, private network names (`localhost`, `.internal`, `.local`) and URLs with a login in them, and connects only to a public address the name resolves to.
2. Run `mailset hooks set --url https://hooks.example.com/mailset`. It prints the signing secret once. Keep it in your secret store as `MAILSET_HOOK_SECRET`.
3. Check each request with the SDK and keep the events. A service that only receives them needs no `MAILSET_KEY`. Every event's fields, a test vector and a verifier for Python, Go, Ruby, PHP and Java are at https://mailset.app/docs/webhooks:

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

const events = await webhooks.verify({
	body: await request.text(),
	headers: request.headers,
	secret: process.env.MAILSET_HOOK_SECRET,
});
```

4. Run `mailset hooks test`. It posts one signed `test` event now and says what your server answered, up to 5 times a minute.

## Check

`mailset hooks get` shows where events go, how many wait for your server, and why the last batch didn't go if one failed.

## Watch out

- Answer 2xx once you've kept the events. Until you do, Mailset posts the same batch again, with the same `Mailset-Delivery` and event ids, for three days, then drops it and tells whoever set the hook.
- Dedupe on `id`. The same message, recipient and happening always has the same id, even when the provider reports it twice. An `unsubscribed` event comes once per opt-out, and someone you let back in who leaves again has a new id.
- Mailset doesn't follow redirects: a 3xx counts as not taken, so set the new URL when a hook moves. Mailset reads nothing of your server's answer but its status, and gives up on a post after 15 seconds.
- Pass the body exactly as it arrived. The signature covers those bytes, and one older than 5 minutes is refused, so a captured request can't be replayed later.
- `mailset hooks rotate` makes a new secret and the old one stops at once. `mailset hooks remove` stops the events and drops what was waiting.
- Only mail an app key sends has events. Campaigns have their own hook: `mailset campaigns hook set`.

---

© 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