Events for your product's mail

A signed webhook that says what became of each message your product sent.

mailset guide product-events
4 stepsOn this page
  1. What you get
  2. Steps
  3. Setup
  4. 1Pick a public https URL
  5. 2Set the hook, keep its secret
  6. 3Verify and keep each event
  7. 4Send yourself a test event
  8. Check
  9. Watch out

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. Install the CLI and sign in

    Sign inSign in with a passkey

    Press Sign in with a passkey and approve it on this device, your phone or a password manager. Mailset has no passwords.

    Open in Mailset

    The command

    Install the CLI on macOS or Linux with brew install intenseloop/tap/mailset or npm install -g @mailset/cli.

    Run mailset login, open the link it prints and approve with your passkey.

    In a terminal, login also offers your agents the Mailset skill; mailset agents add does it later.

    Install the CLI on macOS or Linux with brew install intenseloop/tap/mailset or npm install -g @mailset/cli.

    Run mailset login, open the link it prints and approve with your passkey.

    In a terminal, login also offers your agents the Mailset skill; mailset agents add does it later.

  2. Pick a public https URL

    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.

    Where events can go
  3. Set the hook, keep its secret

    SettingsDevelopersHook URL

    Paste your https URL into Hook URL and press Set the hook. Copy the signing secret it shows once into your secret store.

    Open in Mailset

    The command

    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.

    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.

  4. Verify and keep each event

    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 mailset.app/docs/webhooks:

    import { webhooks } from 'mailset';
    
    const events = await webhooks.verify({
    	body: await request.text(),
    	headers: request.headers,
    	secret: process.env.MAILSET_HOOK_SECRET,
    });
    
    Your webhook
  5. Send yourself a test event

    SettingsDevelopersSend a test

    Press Send a test. Mailset posts one signed test event to your hook now and says whether your server took it, or what went wrong.

    Open in Mailset

    The command

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

    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.