Skip to content
Tinbox

tutorials

Implementing one-click unsubscribe and List-Unsubscribe headers

October 16, 2026

#list-unsubscribe#rfc-8058#deliverability#unsubscribe#tutorial
Subscriber cards separate into groups with an open path to leave.

A recipient who wants out should get out in one tap, and the mailbox provider should be able to do it for them without opening your page. Get the List-Unsubscribe and List-Unsubscribe-Post headers slightly wrong and Gmail either hides the unsubscribe link or quietly counts your mail against you. The spec (RFC 8058) is short, but the POST flow is the part everyone botches.

One-click unsubscribe is one of those features that is trivial to describe and easy to get subtly, silently wrong. You add a header, it looks right, mail sends, and you never find out that Gmail decided your List-Unsubscribe was untrustworthy until your bulk mail starts landing in spam. There is no error. There is no bounce. The header just does nothing.

This is a from-scratch implementation of RFC 8058 one-click unsubscribe: the two headers, the signed token so the POST needs no login, the endpoint that has to act on a POST and not a GET, and the DKIM detail that decides whether providers trust any of it. Then, at the end, the shortcut if you would rather not own this glue.

What headers do I need for one-click unsubscribe?

Two headers, and they work as a pair. List-Unsubscribe carries the address(es) a recipient can use to opt out, and List-Unsubscribe-Post declares that the HTTPS one of those addresses supports an automated one-click POST. Without the second header, the first is just an old-style "here's a link" hint that the provider may or may not surface.

Here is what a correct pair looks like on the wire:

List-Unsubscribe: <https://mail.yourdomain.com/u/eyJzdWIiOiJ1XzQyIn0.9f3c...>, <mailto:unsubscribe@yourdomain.com?subject=unsubscribe>
List-Unsubscribe-Post: List-Unsubscribe=One-Click

Three rules that are not optional:

  • Each URI in List-Unsubscribe is wrapped in angle brackets and the list is comma-separated. Provide both an https: and a mailto: URI when you can: the HTTPS one drives one-click, the mailto is a fallback for clients that only do mailto.
  • List-Unsubscribe-Post must be the literal string List-Unsubscribe=One-Click. Not one-click, not One-click, not with extra parameters. Providers string-match it.
  • Both headers must be inside your DKIM-signed header set. If a provider cannot verify that these headers were not injected in transit, it will not act on them automatically. This is the single most common reason a "correct-looking" header is ignored.

List-Unsubscribe predates RFC 8058 by decades (it is from RFC 2369, 1998). What RFC 8058 added in 2017 is the -Post header and the requirement that the HTTPS endpoint accept an automated POST. Adding the old header alone gets you the mailto fallback but not the clean in-client "Unsubscribe" button that providers now show at the top of a message.

Does one-click unsubscribe use GET or POST?

POST. This is the rule that breaks the most implementations. When a recipient clicks the provider-rendered unsubscribe button, the mailbox provider's servers send an HTTP POST to your https: URI with the body List-Unsubscribe=One-Click. Your endpoint must unsubscribe the recipient from that POST alone: no follow-up page, no second confirmation click, no login.

The POST that arrives at your endpoint looks like this:

POST /u/eyJzdWIiOiJ1XzQyIn0.9f3c... HTTP/1.1
Host: mail.yourdomain.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 26

List-Unsubscribe=One-Click

Note what is not there: no cookies, no Authorization header, no session. The provider is making this request on its own infrastructure, not in the user's browser, so anything that depends on the recipient being logged in to your app is useless here. The only thing identifying the recipient is the path of the URL you generated.

A GET to the same URL is fine and recommended as a human fallback (someone clicking a textual "unsubscribe" link in the body), but the GET must not perform the unsubscribe by itself without a confirmation step, because email clients and security scanners pre-fetch links with GET and would unsubscribe people who never asked. Mutating state on a GET is the second-classic mistake: a link-prefetcher silently unsubscribes half your list.

So the contract is:

  • POST with body List-Unsubscribe=One-Click → unsubscribe immediately, return 2xx.
  • GET → show a confirmation page; only unsubscribe after the human confirms (or after a second POST from that page).

How does the endpoint know who to unsubscribe with no login?

The recipient's identity is baked into the URL as a signed token, minted when you render the message. Because the provider's POST carries no auth, the URL has to be self-authenticating: you encode "subscriber X, list Y" into a token, sign it so it cannot be forged or edited, and verify the signature when the POST arrives. The token is the credential.

The cheapest robust option is an HMAC over the payload. No database lookup is needed to validate it, which matters because this endpoint can get hit hard.

// token.ts: sign and verify an unsubscribe token with HMAC-SHA256.
// Runs on the Workers runtime (WebCrypto), Node 18+, or Deno.

function b64url(bytes: ArrayBuffer | Uint8Array): string {
  const u8 = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
  let s = "";
  for (const b of u8) s += String.fromCharCode(b);
  return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}

function fromB64url(s: string): Uint8Array {
  const pad = s.length % 4 === 0 ? "" : "=".repeat(4 - (s.length % 4));
  const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") + pad);
  return Uint8Array.from(bin, (c) => c.charCodeAt(0));
}

async function key(secret: string): Promise<CryptoKey> {
  return crypto.subtle.importKey(
    "raw",
    new TextEncoder().encode(secret),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["sign", "verify"],
  );
}

export interface UnsubClaims {
  sub: string; // subscriber id
  lst: string; // list id
  exp: number; // unix seconds; tokens are long-lived but not eternal
}

export async function signUnsubToken(claims: UnsubClaims, secret: string): Promise<string> {
  const payload = b64url(new TextEncoder().encode(JSON.stringify(claims)));
  const sig = await crypto.subtle.sign("HMAC", await key(secret), new TextEncoder().encode(payload));
  return `${payload}.${b64url(sig)}`;
}

export async function verifyUnsubToken(token: string, secret: string): Promise<UnsubClaims | null> {
  const dot = token.indexOf(".");
  if (dot < 0) return null;
  const payload = token.slice(0, dot);
  const sig = fromB64url(token.slice(dot + 1));
  const ok = await crypto.subtle.verify(
    "HMAC",
    await key(secret),
    sig,
    new TextEncoder().encode(payload),
  );
  if (!ok) return null;
  const claims = JSON.parse(new TextDecoder().decode(fromB64url(payload))) as UnsubClaims;
  if (claims.exp < Math.floor(Date.now() / 1000)) return null;
  return claims;
}

crypto.subtle.verify does a constant-time comparison, so you are not hand-rolling a timing-unsafe === on the signature. Keep the secret out of the codebase (an env var or a Workers secret). Give tokens a long but finite expiry, say 400 days, so a years-old archived email's link still works but a leaked token does not last forever.

Then, when rendering a message, mint the token and build the headers:

import { signUnsubToken } from "./token";

async function unsubscribeHeaders(
  subscriberId: string,
  listId: string,
  env: { UNSUB_SECRET: string },
): Promise<Record<string, string>> {
  const token = await signUnsubToken(
    { sub: subscriberId, lst: listId, exp: Math.floor(Date.now() / 1000) + 400 * 86400 },
    env.UNSUB_SECRET,
  );
  const httpsUri = `https://mail.yourdomain.com/u/${token}`;
  const mailtoUri = `mailto:unsubscribe@yourdomain.com?subject=unsub:${subscriberId}:${listId}`;
  return {
    "List-Unsubscribe": `<${httpsUri}>, <${mailtoUri}>`,
    "List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
  };
}

How do I implement the POST endpoint?

Accept an unauthenticated POST, verify the token, mark the subscriber unsubscribed idempotently, and return 200 with no body and no redirect. The whole handler is small; the discipline is in what it must not do (no auth, no redirect, no confirmation page on the POST path).

Here is a complete handler on a Cloudflare Worker using Hono, with a D1 table for subscriber state:

// src/unsubscribe.ts
import { Hono } from "hono";
import { verifyUnsubToken } from "./token";

interface Env {
  DB: D1Database;
  UNSUB_SECRET: string;
}

const app = new Hono<{ Bindings: Env }>();

// The one-click POST target. No auth, no session, no redirect.
app.post("/u/:token", async (c) => {
  const claims = await verifyUnsubToken(c.req.param("token"), c.env.UNSUB_SECRET);
  if (!claims) {
    // Bad or expired signature. Do not leak which; just refuse.
    return c.text("invalid token", 400);
  }

  // The provider sends body "List-Unsubscribe=One-Click". We accept it,
  // but we do not require it: the signed token is the real proof of intent.
  // Unsubscribe is idempotent: a second POST is a no-op, still 200.
  await c.env.DB.prepare(
    `UPDATE subscriptions
        SET status = 'unsubscribed', unsubscribed_at = ?3
      WHERE subscriber_id = ?1 AND list_id = ?2 AND status != 'unsubscribed'`,
  )
    .bind(claims.sub, claims.lst, Date.now())
    .run();

  // RFC 8058: respond 2xx with no required body. No redirect, no page.
  return c.body(null, 200);
});

// Human fallback on GET: show a page, do NOT unsubscribe on the GET itself
// (link prefetchers issue GETs). Unsubscribe only when the human confirms.
app.get("/u/:token", async (c) => {
  const claims = await verifyUnsubToken(c.req.param("token"), c.env.UNSUB_SECRET);
  if (!claims) return c.html("<p>This unsubscribe link is invalid or expired.</p>", 400);
  return c.html(`
    <p>Unsubscribe from this list?</p>
    <form method="POST" action="/u/${c.req.param("token")}">
      <button type="submit">Yes, unsubscribe me</button>
    </form>
  `);
});

export default app;

The key decisions, stated plainly:

  • The POST does not require the List-Unsubscribe=One-Click body to be present. The signed token already proves intent. Some providers send the body, some send slightly different things; do not reject on body contents.
  • Unsubscribe is idempotent. The status != 'unsubscribed' guard means a duplicate POST changes nothing and still returns 200. Providers and retries can hit this twice.
  • The GET shows a form; only the POST mutates. That keeps a Gmail or Outlook safety scanner from unsubscribing people by prefetching the link.

Why must the headers be covered by DKIM?

Because a receiver that cannot verify the headers were not injected in transit will refuse to act on the one-click POST. List-Unsubscribe and List-Unsubscribe-Post are instructions to the mailbox provider; if a man-in-the-middle could add or rewrite them, they would be an attack vector, so providers only trust them when DKIM signs them. Leaving them out of the signed set is why a textbook-correct header gets silently ignored.

In your DKIM signer, add both header names to the signed header list (the h= tag). With a typical signer config that looks like:

h=from:to:subject:date:list-unsubscribe:list-unsubscribe-post:mime-version:content-type

If you are using a sending library, find where it builds the DKIM h= list and make sure both header names are in it. If you sign mail at the edge and are still standing up your auth records, the broader setup is covered in the SPF, DKIM, and DMARC setup guide; the headers here ride on top of a working DKIM signature.

How do I test it without sending real campaigns?

Test the POST with curl against your deployed endpoint, then send one real message to an inbox tester to confirm the headers survive signing and parse correctly. Two checks: the endpoint behaves, and the headers actually arrive intact and signed.

First, the endpoint, locally:

npx wrangler dev
# Simulate the provider's one-click POST. Use a token you minted.
curl -i -X POST "http://localhost:8787/u/eyJzdWIiOiJ1XzQyIn0.9f3c..." \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data "List-Unsubscribe=One-Click"

A correct response:

HTTP/1.1 200 OK
content-length: 0

A common wrong response, if you left a redirect or a render in the POST path:

HTTP/1.1 302 Found
location: /unsubscribed

That 302 is a bug. RFC 8058 says respond 2xx directly; a redirect makes some providers treat the action as incomplete. Strip it from the POST path.

Then verify the headers on a delivered message. Send one campaign-shaped email to a service like mail-tester.com or to your own Gmail, open the raw source, and confirm:

List-Unsubscribe: <https://mail.yourdomain.com/u/...>, <mailto:unsubscribe@yourdomain.com?subject=...>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
DKIM-Signature: v=1; a=rsa-sha256; ... h=from:to:subject:date:list-unsubscribe:list-unsubscribe-post:...

If list-unsubscribe and list-unsubscribe-post do not appear in the DKIM h= tag, that is your problem regardless of how perfect the headers look. In Gmail specifically, a correctly-signed pair surfaces an "Unsubscribe" link next to the sender name at the top of the message; if that link is missing, the pair is being rejected.

Common failure modes

Gmail shows no "Unsubscribe" link even though I set the header

Either List-Unsubscribe-Post is missing or misspelled (it must be exactly List-Unsubscribe=One-Click), or the headers are not in the DKIM h= set, or you put them on transactional mail where Gmail does not render the control. Fix the header set first, then re-check.

A chunk of my list got unsubscribed overnight with no clicks

You are mutating state on the GET, and a mail client or security scanner prefetched the links. Move the unsubscribe to POST-only and make the GET show a confirmation form.

The provider's POST returns 401/403 from my endpoint

Your route is behind auth middleware. The one-click POST is unauthenticated by design; the signed token in the URL is the credential. Exempt the /u/:token route from your auth layer.

Tokens stop working after a deploy

You rotated UNSUB_SECRET, which invalidates every previously-signed token in already-sent mail. Keep the secret stable, and if you must rotate, support verifying against the previous secret for a transition window.

The POST does a 302 redirect to a "you're unsubscribed" page

Some providers treat the redirect as the action not completing. Respond 2xx directly from the POST. Show the confirmation page on the GET fallback instead.

The shortcut: Tinbox sets these headers for you

Everything above is the correct implementation, and it is also a meaningful amount to own and keep correct: signed tokens, an unauthenticated POST endpoint, the DKIM header inclusion, idempotency, and a GET fallback that does not self-trigger. Bulk mail also has to satisfy the wider Gmail and Yahoo bulk sender requirements, of which one-click unsubscribe is one line item; the bulk sender checklist turns those rules into boxes to tick, and the pre-send checklist catches the rest before your first campaign. If you would rather not maintain this plumbing, this is exactly what Tinbox handles, running in your own Cloudflare account.

npx tinbox init yourdomain.com

Tinbox signs List-Unsubscribe and List-Unsubscribe-Post on every campaign and includes them in the DKIM signature automatically, hosts the one-click POST endpoint, and writes the unsubscribe straight into your own D1 subscriber table so the suppression is yours, not a vendor's. Sending a campaign carries the headers without you wiring any of it:

import { tinbox } from "tinbox/cf";

// One-click unsubscribe headers and the POST endpoint are added automatically.
await tinbox(env).campaigns.send({
  list: "newsletter",
  subject: "August product notes",
  html: renderNewsletter(),
  // tinbox mints the per-recipient signed unsubscribe token, sets both headers,
  // covers them with DKIM, and records opt-outs in your D1 suppression list.
});

Because Tinbox delivers over HTTPS (Cloudflare Workers cannot open outbound port 25 for direct-to-MX SMTP, no port 25), the signing and header logic live in the same edge sender that does the delivery, so there is no second service to keep in sync. For the deliverability picture this header sits inside, see the deliverability guide, and if you are weighing owning this against a hosted marketing tool, here is an honest comparison.

Deploy this yourself: npx tinbox init yourdomain.com. The unsubscribe, suppression, and DKIM configuration is in the Tinbox docs.

Frequently asked questions

What headers do I need for one-click unsubscribe?

Two. List-Unsubscribe carries one or two URIs, ideally both a mailto: address and an https: URL, in angle brackets. List-Unsubscribe-Post must be exactly 'List-Unsubscribe=One-Click'. Both must be covered by your DKIM signature. The presence of List-Unsubscribe-Post is what tells the mailbox provider the HTTPS link supports an automated POST rather than opening a page.

Does one-click unsubscribe use GET or POST?

POST. RFC 8058 requires the mailbox provider to send an HTTP POST to the https: URI from List-Unsubscribe, with the body 'List-Unsubscribe=One-Click'. Your endpoint must act on that POST alone, with no GET, no login, and no confirmation click. A GET to the same URL is still useful as the human-facing fallback, but the automated flow is POST-only.

How does the unsubscribe endpoint know who to unsubscribe if there is no login?

The recipient identity is encoded in the URL itself as a signed token. When you generate each message, you mint a token (for example an HMAC or a short-lived JWT) binding the subscriber id and the list, embed it in the https: URI, and verify the signature on POST. No session or auth is involved because the signed token is the credential.

Do Gmail and Yahoo require one-click unsubscribe?

Yes, for bulk senders. Since the 2024 Gmail and Yahoo bulk sender rules, senders above the volume threshold must support one-click unsubscribe via List-Unsubscribe and List-Unsubscribe-Post, honor the request within two days, and keep spam complaint rates low. Missing or broken headers can get bulk mail throttled or rejected.

Why does my List-Unsubscribe header get ignored?

Usual causes: the header is not inside the DKIM-signed header set, so providers distrust it; List-Unsubscribe-Post is missing or misspelled, so the link is treated as a page not a one-click action; the https: endpoint returns a redirect or a confirmation page instead of acting on the POST; or you put the header on transactional mail that providers do not surface an unsubscribe UI for.