Transactional and promotional mail

Which mode your product’s mail takes in the SDK, and what each one needs.

mailset guide sending-modes
5 stepsOn this page
  1. Steps
  2. Setup
  3. 1Make your product’s key
  4. 2Give newsletters a subdomain
  5. 3Store both keys as secrets
  6. 4Install the SDK and send
  7. 5Check the key once a day
  8. Check
  9. Watch out

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. 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. Make your product’s key

    SettingsDevelopersMake a key

    Press Make a key, name it, pick a mailbox or a sending domain’s addresses and approve with your passkey. Copy the MAILSET_KEY it shows once.

    Open in Mailset

    The command

    Make a key for your product's own mail: mailset keys create --send --mailbox moc.elpmaxe@olleh --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 moc.elpmaxe@olleh --name "Example API".

    Make a key for your product's own mail: mailset keys create --send --mailbox moc.elpmaxe@olleh --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 moc.elpmaxe@olleh --name "Example API".

  3. Give newsletters a subdomain

    A sending-only domain is added with the command.

    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 moc.elpmaxe.swen@swen --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.

    Hand it to your agent

    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 moc.elpmaxe.swen@swen --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.

    A sender for newsletters
  4. Store both keys as secrets

    Keep each printed MAILSET_KEY in your secret store.

    App key
  5. Install the SDK and send

    Install the SDK with npm install mailset and send.

    The docs have the rest: the SDK at mailset.app/docs/sdk, promotional mail and its unsubscribe at mailset.app/docs/recipes/unsubscribes, batches at mailset.app/docs/recipes/batches, deliverBy at mailset.app/docs/recipes/deadlines, idempotencyKey at mailset.app/docs/recipes/retries, and a language with no SDK at mailset.app/docs/authentication/http.

    import { Mailset } from 'mailset';
    
    // Reads MAILSET_KEY from the environment.
    const mailset = new Mailset();
    
    await mailset.send({
    	from: 'Example <moc.elpmaxe@olleh>',
    	to: 'gro.elpmaxe@ana',
    	subject: 'Your Example code',
    	text: 'Your code is 123456.',
    });
    
    Ana’s inbox
  6. Check the key once a day

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

    mailset.key.check()

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 gro.elpmaxe@ana, or name the mailbox for a mailbox key's mail.