Skip to content
Tinbox

tutorials

How to migrate from Resend to your own Cloudflare sender

October 12, 2026

#resend#cloudflare-workers#transactional-email#migration#tinbox
Message history moves across a paper bridge between two archives.

You like Resend. The SDK is clean, the dashboard is honest, delivery just works. But the bill scales with every email, your sending data lives in someone else's database, and you are already all-in on Cloudflare. You want the DX without the dependency.

To migrate from Resend to a self-hosted Cloudflare sender, you move the send behind one adapter, stand up an endpoint that speaks Resend's request shape on your own Cloudflare account, re-verify your sending domain in DNS, and cut over by changing a base URL and an API key. The send-site code barely moves because the request body is nearly identical. What you gain is ownership of the delivery path and your data, and the end of per-email pricing; the standalone case for that is in why owning your sending domain beats owning the provider.

This is a migration guide, so it is honest about the work. Resend solved real problems for you: DKIM signing, suppression lists, retries, bounce handling, a clean SDK. Moving off it means you now own those problems. The good news is that on Cloudflare they are tractable, and the request shape you already coded against is preserved. Let's map it concept for concept, do the manual cutover, then show the short version.

What does Resend actually do for you that you have to replace?

Resend gives you five things you have to account for before you migrate: a send API with a verified from, automatic DKIM signing, a suppression list, retry/bounce handling, and webhooks for delivery events. Map each one to its self-hosted equivalent before you touch code, or you will discover the gap in production.

Here is the honest inventory. Pull up your Resend usage and check which of these you actually rely on:

Resend conceptWhat it doesSelf-hosted equivalent
resend.emails.send()POST a single email, returns an idPOST /api/send/emails on your Worker
resend.batch.send()Up to 100 emails in one callBatch endpoint or a Queue consumer fan-out
Verified domainSPF + DKIM published, signs your mailYou publish new SPF include + DKIM CNAME
Suppression listDrops mail to bounced/complained addressesYour own suppression table in D1
Idempotency keysDedupes retried sendsidempotency_key on the request body
Webhooksemail.sent, email.delivered, email.bouncedYour own webhook emitter + signature scheme
Audiences / broadcastsMarketing lists and campaignsSeparate concern (see below)

A note on scope: Resend's transactional API and its Audiences/Broadcasts (marketing) feature are two different jobs. This guide covers the transactional sender, which is what resend.emails.send() hits. If you also use Resend for newsletters, that is a separate migration with its own list-export and unsubscribe concerns; treat it on its own track.

The single most important line in that table is DKIM. Resend signs your outbound mail with a key it controls, published as a CNAME in your DNS. Your new sender needs its own key. You cannot reuse Resend's. This is the one part of the migration that touches the public internet and takes real time, so plan it first.

How do I find every place my code sends through Resend?

Grep for the send call and the SDK import, then list every call site. The goal is to know exactly how many places you have to touch, because the whole strategy depends on funneling them through one adapter.

# Find direct send calls
rg "resend\.(emails|batch)\.send" --type ts

# Find the SDK import and client construction
rg "from ['\"]resend['\"]|new Resend\(" --type ts

# Find webhook handlers (delivery events)
rg "resend|svix" src/**/webhooks/**

You will usually find one of two patterns. Either there is a single lib/email.ts that everything imports (lucky you, the migration is one file), or resend.emails.send() is sprinkled across route handlers (less lucky, but the first step fixes that).

Either way, before you change the sender, refactor so every send goes through one function. This is good hygiene independent of the migration, and it makes the cutover a one-line change:

// lib/email.ts  (the only file that knows which sender you use)
import { Resend } from "resend";

const resend = new Resend(process.env.RESEND_API_KEY);

export async function sendEmail(input: {
  from: string;
  to: string | string[];
  subject: string;
  html?: string;
  text?: string;
  replyTo?: string;
}) {
  const { data, error } = await resend.emails.send({
    from: input.from,
    to: input.to,
    subject: input.subject,
    html: input.html,
    text: input.text,
    reply_to: input.replyTo,
  });
  if (error) throw new Error(error.message);
  return { id: data!.id };
}

Now the rest of your codebase calls sendEmail(...) and has no idea what is behind it. That is the whole trick. The migration becomes: change the body of this one function.

How do I stand up a Resend-compatible sender on Cloudflare?

For a Resend-compatible surface, expose an HTTPS endpoint on your own Cloudflare account that accepts the Resend-shaped body and dispatches the mail. Workers cannot deliver direct to recipient MX servers because outbound port 25 is blocked. Workers do expose connect() to allowed third-party submission services, but Node SMTP packages are not automatically compatible, and Cloudflare's own SMTP endpoint is unreachable from Worker TCP. The native Email Service binding or an HTTPS provider API is therefore the appropriate portable implementation behind this compatibility route.

You can build this by hand. The minimum viable version is a Worker that:

  1. Accepts POST /api/send/emails with { from, to, subject, html }.
  2. Checks an API key.
  3. Signs the message with DKIM and dispatches it (via Cloudflare's send_email binding to a verified address, or via an MTA you point it at).
  4. Writes a row to D1 for the log and the idempotency check.

Here is the shape of the hand-rolled route handler, so you can see what you are signing up to own:

// worker/send.ts  (the part you would otherwise build yourself)
import { Hono } from "hono";

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

app.post("/api/send/emails", async (c) => {
  const key = c.req.header("Authorization")?.replace("Bearer ", "");
  if (!(await isValidKey(c.env, key))) return c.json({ error: "unauthorized" }, 401);

  const body = await c.req.json<{
    from: string;
    to: string | string[];
    subject: string;
    html?: string;
    text?: string;
    idempotency_key?: string;
  }>();

  // 1. idempotency: return prior outcome if this key was seen
  // 2. suppression: drop recipients on your bounce/complaint list
  // 3. DKIM-sign and dispatch via send_email binding or MTA
  // 4. write a log row + per-recipient outcome to D1
  const result = await dispatch(c.env, body); // <-- all the hard parts live here
  return c.json(result);
});

Everything interesting is inside dispatch(): DKIM signing, suppression, retries, bounce parsing, per-recipient outcomes, the idempotency store. That is exactly the work Resend was doing for you, and it is the reason most people do not hand-roll this. It is not impossible, but it is a project, not an afternoon.

The shortcut is to deploy a sender that already has all of that. npx tinbox init <domain> stands up a Worker on your Cloudflare account that exposes /api/send/emails with a Resend-shaped body, backed by your own D1 (logs, suppression, idempotency) and Queues (retries):

npx tinbox init mail.yourdomain.com
✔ Detected Cloudflare account: your-account
✔ Created D1 database: tinbox-yourdomain-db
✔ Created R2 bucket: tinbox-yourdomain-r2
✔ Created Queue: tinbox-yourdomain-send
✔ Deployed Worker: tinbox-yourdomain
→ Console: https://mail.yourdomain.com/console
→ Add these DNS records to verify your sending domain:
    SPF   include:  _spf.yourdomain.com
    DKIM  CNAME:     tbx._domainkey.yourdomain.com → ...

One accuracy note so you size this correctly: each tinbox init deploys one brand/domain. You can run many tenants on one Cloudflare account with separate deploys, but a single deployment serves one sending domain today. Multi-domain-per-instance is designed, not shipped. For a Resend migration that is usually fine, you are moving one app's sending.

How do I re-verify my sending domain on the new sender?

Publish the new sender's SPF include and DKIM record in your DNS, and leave Resend's records in place until cutover is done. Domain verification is per-sender: the same domain can be authorized for two senders at once, which is exactly what you want during a migration so no in-flight mail fails DMARC.

Take the records the init command printed (or that the console shows under Settings → Domains) and add them alongside your existing Resend records:

; existing Resend records (KEEP during cutover)
resend._domainkey   CNAME   resend._domainkey.resend.com.

; new self-hosted sender (ADD)
tbx._domainkey      CNAME   tbx._domainkey.yourdomain.com.   ; new DKIM key
@                   TXT     "v=spf1 include:_spf.yourdomain.com include:resend.com ~all"

Note the SPF line includes both senders during the overlap. Once cutover is complete and you have stopped sending through Resend for a few days, remove the include:resend.com and the Resend DKIM CNAME.

Verify before you send a single real message:

# Confirm the new DKIM CNAME resolves
dig +short tbx._domainkey.yourdomain.com CNAME

# Confirm both includes are in SPF
dig +short yourdomain.com TXT | grep spf1

If dig returns nothing for the DKIM record, your DNS has not propagated yet. Wait it out (TTL plus a few minutes) and re-check. Sending before this resolves is the number one cause of a migration that lands in spam. If you want the deeper version of this, the SPF, DKIM, and DMARC setup walkthrough covers each record and how to read the auth results, and verifying a sending domain in DNS covers the verification handshake specifically.

How do I point my code at the new sender without rewriting everything?

Change the body of your one sendEmail() function to POST to the new endpoint with a new key. Because Tinbox's /api/send/emails accepts the same from, to, subject, html, text, and reply_to fields as Resend, the mapping is nearly mechanical.

Here is the same adapter from earlier, now pointed at the self-hosted sender. You can use the @tinbox/sdk client or a plain fetch; the fetch version makes the migration legible:

// lib/email.ts  (same signature, new sender behind it)
const BASE = process.env.TINBOX_BASE_URL!;      // https://mail.yourdomain.com
const KEY = process.env.TINBOX_API_KEY!;        // tbx_...

export async function sendEmail(input: {
  from: string;
  to: string | string[];
  subject: string;
  html?: string;
  text?: string;
  replyTo?: string;
  idempotencyKey?: string;
}) {
  const res = await fetch(`${BASE}/api/send/emails`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${KEY}`,
      "Content-Type": "application/json",
      ...(input.idempotencyKey ? { "Idempotency-Key": input.idempotencyKey } : {}),
    },
    body: JSON.stringify({
      from: input.from,
      to: input.to,
      subject: input.subject,
      html: input.html,
      text: input.text,
      reply_to: input.replyTo,          // same field name as Resend
      idempotency_key: input.idempotencyKey,
    }),
  });

  if (!res.ok) {
    const err = await res.text();
    throw new Error(`send failed ${res.status}: ${err}`);
  }
  return res.json() as Promise<{ id: string; ok: boolean }>;
}

The public signature of sendEmail() did not change. Every caller in your app is untouched. The only diff is inside this function and two new environment variables. That is the payoff for funneling sends through one adapter.

One real difference to handle: the response shape. Resend returns { data: { id }, error }. Tinbox returns { id, ok, recipients, suppressed }, where ok is true only when every recipient ended sent or duplicate. If your code branched on Resend's error field, branch on ok and inspect recipients instead. This is the kind of thing that is invisible until a partial failure, so handle it now:

const result = await sendEmail({ from, to, subject, html });
if (!result.ok) {
  // some recipients were suppressed or failed; inspect, don't assume success
  console.warn("partial send", result);
}

How do I cut over safely and confirm deliverability?

Send to a seed set across the major mailbox providers, read the Authentication-Results header for pass on SPF, DKIM, and DMARC, then ramp real traffic gradually while watching bounces. Do not flip 100% of production to a new sender on a domain it has never sent from; mailbox providers treat sudden volume from a new signing key with suspicion.

The cutover sequence:

  1. Test send. Fire a real message to a Gmail, an Outlook, a Yahoo, and a Proton address you control.
  2. Read the headers. In Gmail, "Show original"; you want spf=pass dkim=pass dmarc=pass for your domain, signed by your new selector.
Authentication-Results: mx.google.com;
  dkim=pass header.i=@yourdomain.com header.s=tbx;
  spf=pass smtp.mailfrom=yourdomain.com;
  dmarc=pass (p=NONE) header.from=yourdomain.com
  1. Ramp. Route a small percentage of real sends to the new endpoint (a feature flag in sendEmail() is enough), watch your bounce and complaint rates, and increase over a few days. The domain already has reputation from sending through Resend, so this is a warm-up of the new key, not a cold start.
  2. Retire Resend. Once all traffic is on the new sender and stable, revoke the Resend API key, remove its SPF include and DKIM CNAME, and cancel the plan.

A common failure mode at this stage: you flip the flag, mail sends, but DMARC says dkim=fail. Almost always this is because the DKIM CNAME had not finished propagating when you tested, or the from domain does not match the signing domain (DMARC alignment). Re-check the dig output from earlier and make sure your from address is on the verified domain, not a subdomain you did not publish a key for. The deliverability guide has the full checklist for reading and fixing these results.

Or skip the hand-rolled parts

You can build the endpoint, the DKIM signer, the suppression table, the idempotency store, the retry queue, and the webhook emitter yourself. People do, and the dispatch() sketch above is the honest skeleton of it. But that is the part of Resend you were paying for, and rebuilding it is a project.

Tinbox is that endpoint, already built, running on your own Cloudflare account: a Resend-shaped /api/send/emails, your own D1 for logs and suppression, Queues for retries, and DKIM signing wired in. The migration becomes the three things this guide is actually about: publish DNS records, change one base URL and one key, and ramp. There is no per-email price; you pay Cloudflare for the underlying Workers, D1, R2, and Queues usage, which for most transactional volumes is small. If you want the broader picture of what you are adopting (the inbox, console, and AI agent that ship alongside the sender), start with the Tinbox overview, and if you are weighing the move at all, the self-hosted Resend alternative comparison lays out the trade-offs without the sales pitch. If you would rather survey the whole field before committing, ten transactional email API alternatives worth comparing ranks Resend against Postmark, SES, and owning delivery yourself.

For the cost math specifically (when a fixed Cloudflare bill beats per-email pricing and when it does not), the transactional email cost breakdown runs the numbers.

Deploy this yourself: npx tinbox init mail.yourdomain.com, then read the migration notes in the docs for the field-by-field mapping from Resend's API to /api/send/emails.

Frequently asked questions

How do I migrate from Resend to a self-hosted sender on Cloudflare?

Stand up a sending endpoint on your own Cloudflare account (a Worker that exposes /api/send/emails), re-verify your sending domain by publishing its SPF include and DKIM CNAME records, then swap your Resend client for a thin adapter that POSTs the same from/to/subject/html body to the new endpoint with your own API key. The cutover is a base-URL and key change at one or two call sites.

Will my Resend code break when I move to a self-hosted sender?

Mostly no, if you isolate the send behind one function. Resend's send body (from, to, subject, html, text, reply_to, cc, bcc) maps almost one-to-one onto Tinbox's /api/send/emails body, so the request shape is preserved. What changes is the base URL, the API key, and webhook signature verification, which is why you wrap the SDK rather than scatter resend.emails.send() across the codebase.

Do I have to re-verify my sending domain after leaving Resend?

Yes. Domain verification is per-sender: the new sender needs its own SPF include and its own DKIM key published in your DNS. You keep the same domain, but you publish a new DKIM CNAME (or TXT) for the self-hosted sender and add its SPF include. Plan for DNS propagation and a short period where both senders are authorized so in-flight mail still passes DMARC.

Is a self-hosted Cloudflare sender as deliverable as Resend?

Deliverability comes from authentication and sending reputation, not from the vendor's logo. If you publish correct SPF, DKIM, and DMARC, warm the domain gradually, and handle bounces and unsubscribes, a self-hosted sender on Cloudflare reaches inboxes the same way Resend does. The work Resend did for you (DKIM signing, suppression, retries) is work you now own, which a tool like Tinbox handles for you.

What does it cost to run my own sender versus Resend?

A self-hosted sender on Cloudflare has no per-email price. You pay Cloudflare for Workers, D1, R2, and Queues usage, which for most transactional volumes sits inside or just above the free tiers. Resend bills per email above its free tier. The trade is a fixed, low platform cost plus the operational responsibility for delivery, versus a per-message bill with the vendor carrying that responsibility.