{
  "id": 10394128,
  "title": "Cloudflare Email Worker inbox: store every message in D1 in 30 lines",
  "url": "https://urgent.news/2026/09/28/cloudflare-email-worker-inbox-store-every-message-in-d1-in-30-lines",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-28T07:14:09.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/howardzlh/cloudflare-email-worker-inbox-store-every-message-in-d1-in-30-lines-ii1"
  },
  "original_language": "en",
  "account": "Cloudflare Email Worker inbox utilizes 30 lines of TypeScript to store every incoming message in D1. This setup allows for the preservation of messages for later reference. Instead of forwarding the email to a mailbox, the message is written to D1 (and R2 for attachments) by the worker. A small web UI is then used to read the stored messages. The Email Routing system forwards messages, but it does not have a built-in mailbox. This is because Cloudflare's focus is on the edge, not storage. Email Routing accepts the SMTP session, applies routing rules, and then hands the bytes to a destination, which in this case is a Worker. The email() method within the worker exports a function that processes the incoming message. It reads the raw MIME data, parses it, and then stores the message details in D1 using an SQL insert statement. The worker also forwards the message to a verified destination. It's important to note that message.raw is a ReadableStream, not a string, so it must be wrapped in a Response object before it can be read. The forwarding of the message is limited to verified destinations, and unverified addresses will result in a bounce. The setup requires a small web UI to read the stored messages. The configuration is done through the Wrangler CLI, and the routing rule is set up in the Cloudflare dashboard.",
  "summary": "Originally published at guushu.com/notes . I keep the original updated, so this copy may lag. Email Routing forwards a message and keeps nothing. If you want a copy you can search later, point the routing rule at a Worker, write the message to D1, and forward it on. That's a Cloudflare Email Worker inbox, about 30 lines of TypeScript. Three self-hosted projects already ship that shape, two open…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}