D1, R2 & Resend · Free guide

Building an email opt-in subscriber list in Cloudflare D1 with 1-click unsubscribe

To build your own email audience on a static site without renting third-party SaaS list platforms, gate downloads behind a Turnstile-verified modal that requires an unchecked-by-default opt-in checkbox, upserts subscribers into Cloudflare D1 with a unique UUID unsubscribe_token, and exposes a instant /api/unsubscribe endpoint.

By StaticLaunch · Four Media Group LLC

Keep consent explicit and bot-free from day one

Never pre-check marketing consent boxes or skip bot verification—spam signups ruin sender reputation on Resend immediately. Require Turnstile verification, enforce valid email syntax server-side, and log the exact opt-in timestamp cleanly.

Avoid annoying returning visitors with signed HMAC receipts

Once a user opts in, issue a compact HMAC-SHA256 receipt stored alongside localStorage so subsequent resource downloads take a single click and record download analytics cleanly via mode: 'record-download'.

Include 1-click unsubscribe links in every Resend broadcast

Store a random unsubscribe_token per subscriber row and expose GET/POST https://yourdomain.com/api/unsubscribe?token=... that immediately sets updates_opt_in = 0 so List-Unsubscribe headers stay compliant.

Example
CREATE TABLE IF NOT EXISTS template_subscribers (
  id TEXT PRIMARY KEY,
  email TEXT NOT NULL UNIQUE,
  updates_opt_in INTEGER NOT NULL DEFAULT 1,
  unsubscribe_token TEXT NOT NULL UNIQUE,
  created_at TEXT NOT NULL,
  unsubscribed_at TEXT
);

Common questions

How do I export D1 subscribers to send updates with Resend?

Query WHERE updates_opt_in = 1 AND unsubscribed_at IS NULL cleanly via Wrangler or trigger a periodic Worker calling Resend's batch/broadcast endpoints automatically.

Should privacy policies disclose D1 email storage explicitly?

Yes. Document what fields you collect, how unsubscribe and deletion work, and provide a clearing control in your browser privacy choices.

References

Provider interfaces and limits can change. Consult the original documentation before changing production settings.