Dashboard

Unsubscribe Link for an AI-Built App: Do It Right

Add an unsubscribe link for an AI-built app that works: one-click headers, a suppression table, CAN-SPAM basics, and a prompt your coding agent can follow.

Steve Jefferson
Steve Jefferson
Developer Advocate
13 October 20261 min read

An unsubscribe link for an AI-built app needs three parts, not one: a visible link in the email footer, a one-click header that mail apps can use, and a suppression table that your sending code checks before every marketing email. AI coding agents tend to build the first part and leave the other two out, so the link looks right and then the emails keep arriving.

This guide gives you the spec to hand your agent, the rules behind it, and a short test to run before you send to real people.

The US rule most small senders meet first is the CAN-SPAM Act. The FTC's compliance guide for business says your opt-out mechanism must keep working for at least 30 days after you send a message, and that you must honor an opt-out request within 10 business days. You may not charge a fee, ask for anything beyond an email address, or require more than a reply email or a visit to a single web page.

Treat those as the floor. In practice you want the unsubscribe to take effect immediately, because the cost of a late stop is a spam complaint, and complaints hurt every email your app sends.

If your app sends mail, you will also want to read why emails from your AI-built app go to spam and how to add email sending to an AI-built app, which cover the sending setup this builds on.

Every marketing email gets a footer link that points to a page on your own domain. The link carries a signed token, not an email address:

text
https://yourapp.com/unsubscribe?token=<signed-token>

The page should show the address being removed, one button to confirm, and a clear success message. No login, no survey, no "are you sure" maze. The token should be unique to that recipient and that message, and it should be impossible to guess.

Part two: one-click headers

Mail apps can show their own "Unsubscribe" button if your emails include the right headers. The standard is RFC 8058, which defines a one-click method built on two headers:

text
List-Unsubscribe: <https://yourapp.com/unsubscribe/one-click?token=abc123>
List-Unsubscribe-Post: List-Unsubscribe=One-Click

The RFC sets these conditions, among others:

  • The List-Unsubscribe header must contain one HTTPS URI.

  • Your server must accept POST requests at that URI, and the endpoint must not return a redirect.

  • The message must carry a valid DKIM signature that covers both headers.

The reason it uses a POST is stated in the RFC itself: mail software sometimes fetches URLs found in headers, which could unsubscribe people by accident. So a GET to the one-click address must not unsubscribe anyone. Only the POST does.

Google also expects this from larger senders. Its help page for bulk senders says marketing and subscribed messages from those sending over 5,000 messages a day must support one-click unsubscribe, and that spam rate in Postmaster Tools should stay below 0.30%. If you are nowhere near that volume, add the headers anyway. It costs a few lines of code.

Part three: a suppression table

The footer link and the headers both do the same thing at the end: they write a row to a table. Every send checks that table first.

sql
create table email_suppressions (
  email text primary key,
  reason text not null,        -- 'unsubscribed', 'bounced', 'complaint'
  created_at timestamptz default now()
);

Your sending function must refuse to send marketing mail to any address in it. Make that check a single function that every sender calls, so a new email type added later cannot bypass it.

Keep two lists apart. Marketing and product-news emails honour unsubscribes. Messages a user needs to operate their account, such as a password reset, are a different category and should not be sent through the marketing path. Decide which is which when you design each email, not afterwards.

The prompt to give your coding agent

text
Add unsubscribe support to our email sending.

1. Every marketing email gets a footer link to /unsubscribe?token=<signed token>.
2. Add headers List-Unsubscribe (one HTTPS URI) and List-Unsubscribe-Post: List-Unsubscribe=One-Click.
3. Create POST /unsubscribe/one-click that verifies the token and adds the address to an email_suppressions table. It must not redirect. A GET must show the confirm page and change nothing.
4. All marketing sends must go through one function that checks email_suppressions first.
5. Write tests for: a valid token, a tampered token, a repeated unsubscribe, and a GET that does not unsubscribe.

If your agent suggests putting the email address in the URL, say no. A signed token avoids leaking addresses and stops people unsubscribing someone else.

Test it before real people do

Send yourself a marketing email and check four things: the footer link works without logging in, the Unsubscribe button appears in your mail app, a second email to the same address is blocked, and the address shows up in the suppression table. Then check your privacy policy and any data deletion flow describe what you keep. For the wider build, see our guide to building an app with AI.

Frequently asked questions

Marketing and promotional emails need a working opt-out. Messages a user needs to operate their account, such as a password reset, are a different category. Decide the category for each email type, and check the rules for the countries you send to.

How fast must I process an unsubscribe request?

The FTC guide for CAN-SPAM says you must honor opt-out requests within 10 business days. Process them immediately in code, since a delay only raises your complaint rate.

What is a one-click unsubscribe header?

It is a pair of email headers, List-Unsubscribe and List-Unsubscribe-Post, defined in RFC 8058. They let a mail app unsubscribe someone with a single POST request to your server.

Why must one-click unsubscribe use a POST request?

Mail software sometimes fetches URLs found in headers, so a GET request could unsubscribe people by accident. The RFC specifies a POST so only a deliberate action counts.

Can I ask users why they are leaving?

You can offer an optional question after the unsubscribe is complete. Do not require an answer, a login or any extra step before the unsubscribe takes effect.

How did this land?

About the author

Steve Jefferson
Steve Jefferson

Developer Advocate

Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.