[Skip to content](#main)

[→](/)

[![Avunu](/brand/avunu-logo.svg)![Avunu](/brand/avunu-logo-light.svg)](/)[Services](/services/)[Consulting](/services/consulting/)[ERP](/services/erp/)[Odoo](/services/erp/odoo/)[ERPNext](/services/erp/erpnext/)[Custom software](/services/custom-software/)[Devices & IoT](/services/devices-iot/)[Websites](/services/websites/)[Infrastructure](/services/infrastructure/)[Partners](/partners/)

[Work](/work/)[Open source](/open-source/)[Knowledge base](/kb/)[About](/about/)

[About Avunu](/about/)[Team](/about/team/)[Insights](/insights/)[Contact](/contact/)

[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

- [Services](/services/)[Consulting](/services/consulting/)
- [ERP](/services/erp/)
- [Odoo](/services/erp/odoo/)
- [ERPNext](/services/erp/erpnext/)
- [Custom software](/services/custom-software/)
- [Devices & IoT](/services/devices-iot/)
- [Websites](/services/websites/)
- [Infrastructure](/services/infrastructure/)
- [Partners](/partners/)

[Work](/work/)[Open source](/open-source/)[Knowledge base](/kb/)[About](/about/)

- [About Avunu](/about/)
- [Team](/about/team/)
- [Insights](/insights/)
- [Contact](/contact/)

[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

[Knowledge base](/kb/)[Email](/kb/email/)Deploy the cloudflare-email-relay Worker

Search the knowledge basePress/

ESC

Jump to

[Browse the knowledge base](/kb/)[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[NixOS](/kb/nixos/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

↵select↑↓navigateescclose

Search the knowledge base

[Skip to the article](#kb-article)[Email](/kb/email/)6 articles

- [Overview](/kb/email/)
- [Deploy the cloudflare-email-relay Worker](/kb/email/deploying-cloudflare-email-relay/)
- [Email without SMTP for business systems](/kb/email/email-without-smtp-for-business-systems/)
- [Send and receive Frappe and ERPNext email through Cloudflare](/kb/email/cloudflare-email-for-frappe-and-erpnext/)
- [Send and receive Odoo email through Cloudflare](/kb/email/cloudflare-email-for-odoo/)
- [Send WordPress email through Cloudflare Email Sending](/kb/email/cloudflare-email-for-wordpress/)
- [Troubleshooting Cloudflare email delivery](/kb/email/troubleshooting-cloudflare-email/)

Other sections[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[NixOS](/kb/nixos/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

In Email: 6 articles

[Overview](/kb/email/)[Deploy the cloudflare-email-relay Worker](/kb/email/deploying-cloudflare-email-relay/)[Email without SMTP for business systems](/kb/email/email-without-smtp-for-business-systems/)[Send and receive Frappe and ERPNext email through Cloudflare](/kb/email/cloudflare-email-for-frappe-and-erpnext/)[Send and receive Odoo email through Cloudflare](/kb/email/cloudflare-email-for-odoo/)[Send WordPress email through Cloudflare Email Sending](/kb/email/cloudflare-email-for-wordpress/)[Troubleshooting Cloudflare email delivery](/kb/email/troubleshooting-cloudflare-email/)

Other sections[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[NixOS](/kb/nixos/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

EmailDeploy the cloudflare-email-relay Worker

Deploy the multi-tenant Cloudflare Email Routing relay Worker with R2, Durable Objects, tenants, secrets, routing rules, the ops API and an end-to-end test.

UpdatedNov 7, 2026

Applies to\@avunu/cloudflare-email-relay 2.0.0Wrangler 4

Tagsemailcloudflareworkersdeployment

Reading time11 min

On this page[How the relay behaves](#how-the-relay-behaves)[Prerequisites](#prerequisites)[Layout of a deployment](#layout-of-a-deployment)[The wrapper](#the-wrapper)[The Wrangler config](#the-wrangler-config)[Create the bucket and set the ops token](#create-the-bucket-and-set-the-ops-token)[Define a tenant](#define-a-tenant)[The tenant table](#the-tenant-table)[The tenant secret](#the-tenant-secret)[Deploy](#deploy)[Route mail to the Worker](#route-mail-to-the-worker)[Use the ops API](#use-the-ops-api)[Verify a test message end to end](#verify-a-test-message-end-to-end)[Reading the result](#reading-the-result)[Test locally first](#test-locally-first)[Related documents](#related-documents)

This document walks you through deploying [cloudflare-email-relay](https://github.com/Avunu/cloudflare-email-relay), the Worker that receives mail from Cloudflare Email Routing and pushes it as a signed HTTPS request to the Odoo or Frappe instance that owns the recipient's domain. Use it when you are standing up a new relay, adding a tenant to an existing one, or checking that a deployment works. For the reasoning behind the design, see [Email Without SMTP for Business Systems](/kb/email/email-without-smtp-for-business-systems/).

## How the relay behaves

Knowing the moving parts makes the deployment steps easier to follow.

**Intake.** Email Routing hands the Worker one message per recipient. The Worker looks up the recipient's domain in a tenant table, writes the raw message to R2, and only then queues it.

**Queue.** Each tenant gets its own SQLite-backed Durable Object. Its alarm pushes queued messages to the ERP, oldest first, ten per pass, and retries failures on a schedule.

**Ops API.** The Worker's `fetch()` handler exposes a small bearer-token API for inspecting and retrying messages.

Because the message is stored before it is pushed, an ERP outage, a wrong secret or a bad deploy delays mail but does not lose it. A recipient whose domain belongs to no tenant, or to a disabled tenant, is rejected during the SMTP conversation. The relay never guesses a tenant.

Outbound mail does not pass through this Worker. Each ERP calls the Cloudflare Email Sending API directly.

## Prerequisites

You need:

A Cloudflare account with R2 enabled. The relay uses SQLite-backed Durable Objects, which Cloudflare offers on the Workers Free plan as well as Workers Paid. Check Cloudflare's current limits against your mail volume. The Email Sending API that your ERPs use for outbound mail requires Workers Paid, but the relay does not call it.

The zone for each mail domain in that same account. Email Routing can only hand mail to a Worker in the account that owns the zone.

Node.js and Wrangler 4 (the repository itself builds against Wrangler `^4.146.0`).

An ERP instance per tenant with its mail-receiving side set up: the [`mail_cloudflare`](https://github.com/Avunu/mail-addons/tree/18.0/mail_cloudflare) addon for Odoo, or [`cloudflare_email_delivery`](https://github.com/Avunu/cloudflare_email_delivery) for Frappe. The setup guides are [Cloudflare Email for Odoo](/kb/email/cloudflare-email-for-odoo/) and [Cloudflare Email for Frappe and ERPNext](/kb/email/cloudflare-email-for-frappe-and-erpnext/).

Note

The relay needs no `nodejs_compat` flag. It uses Web APIs only, so leave `compatibility_flags` out of your config.

## Layout of a deployment

The package holds all of the relay logic. A deployment is a small repository of your own with three files per Worker:

```text
index.ts        the wrapper that builds the relay
tenants.json    the committed tenant table
wrangler.jsonc  Worker name, account, R2 bucket, Durable Object binding and migration
```

The package is `@avunu/cloudflare-email-relay`, published to GitHub Packages (`https://npm.pkg.github.com`). Install it in your deployment repository with `npm install @avunu/cloudflare-email-relay`, after pointing the `@avunu` npm scope at that registry. This document does not cover registry authentication.

### The wrapper

Create `index.ts`:

```
<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">import</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> { createRelay } </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">from</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"@avunu/cloudflare-email-relay"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">import</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> tenants </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">from</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"./tenants.json"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>

<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">const</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">relay</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#D2A8FF;--shiki-light:#8250DF">createRelay</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">({ tenants });</span>

<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">export</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">default</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800"> </span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">relay</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">.</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">handler;</span>
<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">export</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">const</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> { </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">InboxQueue</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> } </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> relay;</span>
```

`createRelay` validates the tenant table when the module loads, so a bad table fails the deploy instead of misrouting mail. The Durable Object class must be re-exported under the exact name `InboxQueue`, because the Wrangler config binds it by that name.

If several Workers share one R2 bucket, pass `keyPrefix` to `createRelay` so their objects do not collide. The default is `inbox/`, and objects are stored as `<keyPrefix><slug>/<id>.eml`.

### The Wrangler config

Create `wrangler.jsonc`:

```
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">{</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"name"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"email-relay"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"main"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"index.ts"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"account_id"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"<ACCOUNT_ID>"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"compatibility_date"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"2026-08-22"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"observability"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: { </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"enabled"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">true</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> },</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"r2_buckets"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: [{ </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"binding"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"INBOX"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"bucket_name"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"email-relay-inbox"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> }],</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"durable_objects"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: {</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"bindings"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: [{ </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"name"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"INBOX_QUEUE"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"class_name"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"InboxQueue"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> }]</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  },</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"migrations"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: [{ </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"tag"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"v1"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"new_sqlite_classes"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: [</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"InboxQueue"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">] }]</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">}</span>
```

Three details matter:

The bindings must be named `INBOX` (R2) and `INBOX_QUEUE` (Durable Object). The code reads them by those names.

The migration uses `new_sqlite_classes`, not `new_classes`, because the queue stores its rows in Durable Object SQLite. Keep the `v1` tag as it is and do not edit it.

There are no `vars`. Every tunable lives in the tenant table, and everything sensitive is a Worker secret.

## Create the bucket and set the ops token

Run these once per Worker.

Create the R2 bucket that the `INBOX` binding points at:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npx</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wrangler</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">r2</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">bucket</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">create</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">email-relay-inbox</span>
```

Add a lifecycle rule as a safety net behind the Worker's own purge:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npx</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wrangler</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">r2</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">bucket</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">lifecycle</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">add</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">email-relay-inbox</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--prefix</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">inbox/</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--expire-days</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">180</span>
```

If you set a different `keyPrefix` in `createRelay`, use that prefix here instead of `inbox/`.

Set the ops token. Generate a long random value first; the Worker ignores any token shorter than 32 characters:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">openssl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">rand</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-hex</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">32</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npx</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wrangler</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">secret</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">put</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">OPS_TOKEN</span>
```

Warning

The lifecycle rule deletes objects regardless of delivery state. If an object disappears before the queue delivers it, the row is marked dead with the error "stored message missing from R2". Keep the expiry well beyond both the retry window (about seven days on the defaults) and the longest `retentionDays` you give any tenant. This follows from how the Worker handles a missing object; the 180 days in the example is the repository's suggested value.

## Define a tenant

A tenant is one ERP instance. Its configuration is split in two: a public row in `tenants.json`, and a secret that holds the inbound URL and key.

### The tenant table

`tenants.json` is an array with one object per tenant:

```
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">[</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  {</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"slug"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"example-co"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"platform"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"odoo"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"domains"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: [</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"example.com"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"*.example.com"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">],</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"enabled"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">true</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"note"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"Example Co, ticket 123"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"retentionDays"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">30</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"maxAttempts"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">32</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"backoffSeconds"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: [</span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">60</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">300</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">900</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">3600</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">21600</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">],</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"deliveryTimeoutSeconds"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">30</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"deliveryDelaySeconds"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">0</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  }</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">]</span>
```

Only `slug`, `platform` and `domains` are required. The other fields show their defaults:

| Field                    | Meaning                                                                                                                                                          |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `slug`                   | Lowercase letters, digits and hyphens, 1 to 63 characters. It names the queue, the R2 prefix and the secret, so never change it after mail has flowed.           |
| `platform`               | `odoo` or `frappe`. It is used for documentation and URL validation only; the delivery contract is the same for both.                                            |
| `domains`                | Recipient domains routed to this tenant, lowercase, internationalized names in punycode. `*.example.com` matches every subdomain but never `example.com` itself. |
| `enabled`                | When `false`, mail is rejected at intake with "Recipient domain is disabled on this relay". The tenant's queue stays reachable.                                  |
| `note`                   | Free text up to 200 characters. The code never reads it.                                                                                                         |
| `retentionDays`          | Days a delivered message stays in R2, from 0 to 3650. `0` purges it as soon as the ERP accepts it.                                                               |
| `maxAttempts`            | Attempts before a message is marked dead. 32 is about seven days on the default schedule.                                                                        |
| `backoffSeconds`         | Delay after each failed attempt. The last value repeats.                                                                                                         |
| `deliveryTimeoutSeconds` | Per-attempt timeout, at most 60.                                                                                                                                 |
| `deliveryDelaySeconds`   | Wait before the first attempt. Leave it at 0 in production.                                                                                                      |

The table as a whole must follow three rules: slugs are unique, each domain belongs to one tenant, and a wildcard may not cover another tenant's domain, exact or wildcard. A table that breaks a rule makes `createRelay` throw. Because tenants cannot overlap, a message never has two possible owners. Within one tenant, an exact domain is matched before a wildcard.

To validate the table in CI without a Worker runtime, use the package's `/tenants` entry point, which runs in plain Node:

```
<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">import</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> { readFileSync } </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">from</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"node:fs"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">import</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> { parseTenantTable } </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">from</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"@avunu/cloudflare-email-relay/tenants"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>

<span style="--shiki-dark:#D2A8FF;--shiki-light:#8250DF">parseTenantTable</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">(</span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">JSON</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">.</span><span style="--shiki-dark:#D2A8FF;--shiki-light:#8250DF">parse</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">(</span><span style="--shiki-dark:#D2A8FF;--shiki-light:#8250DF">readFileSync</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">(</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"tenants.json"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">, </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"utf8"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">)));</span>
```

### The tenant secret

Each tenant has one Worker secret named `TENANT_<SLUG>`: the slug in upper case with hyphens turned into underscores. The slug `example-co` becomes `TENANT_EXAMPLE_CO`.

The value is a JSON string:

```
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">{</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"inboundUrl"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"https://erp.example.com/mail_cloudflare/inbound/<KEY>"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">,</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#7EE787;--shiki-light:#116329">"secret"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">: </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"<SHARED_SECRET>"</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">}</span>
```

`inboundUrl` is the webhook URL your ERP shows you. In Odoo it is the Incoming Mail Server's "Webhook URL". In Frappe it is the Email Account's "Webhook URL". The ERP generates the key embedded in it, so treat the whole URL as a secret.

`secret` is the HMAC key the ERP shows beside the URL. It must be at least 16 characters.

`accessClientId` and `accessClientSecret` are optional and must be set together. Add them only when the inbound route sits behind a Cloudflare Access policy.

Set it with Wrangler and paste the JSON on one line when prompted:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npx</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wrangler</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">secret</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">put</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">TENANT_EXAMPLE_CO</span>
```

The Worker reads each tenant secret fresh on every delivery pass. If a secret is missing or malformed, that tenant's messages stay pending with no attempt charged, and the Worker logs `tenant_config_error` about once a minute. Intake and every other tenant keep working, and fixing the secret needs no redeploy.

## Deploy

From the deployment repository:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npx</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wrangler</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">deploy</span>
```

Changing `tenants.json` (adding a tenant, changing a domain or a tunable) needs a redeploy, because the table is bundled into the Worker. Changing a secret does not.

## Route mail to the Worker

In the Cloudflare dashboard, open the zone, then **Email Routing**, and send the addresses you want to receive (or the catch-all address) to the Worker with the **Send to a Worker** action, choosing your deployed Worker. Do this for every zone whose domains appear in the tenant table.

Domains that match no tenant are still rejected with the SMTP reply "Recipient domain is not served by this relay", so a routing rule for a domain missing from `tenants.json` gets mail refused instead of silently dropped.

## Use the ops API

The ops API lives on the Worker's `workers.dev` hostname. `GET /health` is public and answers `{"ok":true}`. Every other route needs the token:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">curl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-H</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"Authorization: Bearer <OPS_TOKEN>"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">https://email-relay.</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ACCOUNT_SUBDOMAI</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">N</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.workers.dev/tenants</span>
```

If `OPS_TOKEN` is unset or shorter than 32 characters, every route except `/health` answers 404. A missing or wrong token gets 401.

| Route                                          | What it does                                                                                                            |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `GET /tenants`                                 | Every tenant's public config plus counts of `pending`, `delivered`, `rejected` and `dead` messages.                     |
| `GET /tenants/<SLUG>`                          | The same for one tenant.                                                                                                |
| `GET /tenants/<SLUG>/inbox?status=&limit=`     | The tenant's queue rows, newest first. `status` is one of the four states. `limit` defaults to 50 and is capped at 500. |
| `GET /tenants/<SLUG>/inbox/<ID>`               | One row.                                                                                                                |
| `GET /tenants/<SLUG>/inbox/<ID>/raw`           | The stored message as an `.eml` download.                                                                               |
| `POST /tenants/<SLUG>/inbox/<ID>/retry`        | Requeue one row. Returns 202, or 409 if it is already pending.                                                          |
| `POST /tenants/<SLUG>/inbox/retry?status=dead` | Requeue every row in that state. `status` must be `dead` or `rejected`.                                                 |
| `DELETE /tenants/<SLUG>/inbox/<ID>`            | Remove the row and its stored message.                                                                                  |

For another layer of protection, put a Cloudflare Access policy in front of the hostname, or set `workers_dev` to `false` and use a custom route behind Access. Neither needs a code change.

## Verify a test message end to end

Check the pieces in order, from the Worker outward.

Confirm the Worker is up:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">curl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">https://email-relay.</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ACCOUNT_SUBDOMAI</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">N</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.workers.dev/health</span>
```

```text
{"ok":true}
```

Confirm the tenant is in the table and its counts are zero:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">curl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-H</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"Authorization: Bearer <OPS_TOKEN>"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">https://email-relay.</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ACCOUNT_SUBDOMAI</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">N</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.workers.dev/tenants/example-co</span>
```

Send a message from an outside mailbox, such as `jane@example.com`, to an address on the tenant's domain that your Email Routing rule sends to the Worker.

Watch the logs. The Worker writes JSON log lines (observability is on in the config above), which you can read in the dashboard or with `npx wrangler tail`. A healthy message produces `inbox_enqueued` and `email_stored` events, followed by a `delivery_result` event with `"outcome":"delivered"`.

Check the queue:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">curl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-H</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"Authorization: Bearer <OPS_TOKEN>"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"https://email-relay.<ACCOUNT_SUBDOMAIN>.workers.dev/tenants/example-co/inbox?limit=5"</span>
```

The newest row should have status `delivered`. Then confirm in the ERP that the message arrived as a mail record.

Optionally, route a spare domain's addresses to the Worker without adding that domain to the table, then send one message to it. The message should be refused during the SMTP conversation with the reason "Recipient domain is not served by this relay", which the sender's mail system normally reports back as a bounce. This proves unrouted mail is refused, and you will also see an `email_unrouted` log line.

### Reading the result

How the ERP's answer to each attempt changes the row:

| ERP response                                    | Row becomes                                                                   |
| ----------------------------------------------- | ----------------------------------------------------------------------------- |
| Any 2xx                                         | `delivered`                                                                   |
| 408, 429, any 5xx, a timeout or a network error | `pending`, retried on the backoff schedule, then `dead` when attempts run out |
| Any other 4xx, or any 3xx                       | `rejected`, parked for an operator                                            |

Redirects are never followed, because that would replay a signed message to an unvetted origin. A `rejected` row after a first test usually means the wrong secret (often a 401), a wrong or stale key in `inboundUrl` (often a 404), or an `inboundUrl` that redirects. Fix the secret, then requeue the row:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">curl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-X</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">POST</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-H</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"Authorization: Bearer <OPS_TOKEN>"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"https://email-relay.<ACCOUNT_SUBDOMAIN>.workers.dev/tenants/example-co/inbox/retry?status=rejected"</span>
```

## Test locally first

You can run the relay on your machine against a local ERP before touching Cloudflare. In a checkout of the relay repository:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npm</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ci</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">cp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.dev.vars.example</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.dev.vars</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">npm</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">run</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">dev</span>
```

Edit `TENANT_DEV` in `.dev.vars` so `inboundUrl` and `secret` match your local ERP. Then post a sample message to the local Email Routing endpoint:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">curl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-X</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">POST</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'http://localhost:8787/cdn-cgi/local/email?from=jane@example.com&to=support@dev.test'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">\</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-H</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'Content-Type: message/rfc822'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--data-binary</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">@test/fixtures/simple.eml</span>
```

The development table routes `dev.test` and `*.dev.test` to the `dev` tenant.

## Related documents

[Troubleshooting Cloudflare Email](/kb/email/troubleshooting-cloudflare-email/): what to check when mail is delayed, rejected or missing.

[Cloudflare Email for Odoo](/kb/email/cloudflare-email-for-odoo/) and [Cloudflare Email for Frappe and ERPNext](/kb/email/cloudflare-email-for-frappe-and-erpnext/): get the webhook URL and secret that go into a tenant secret.

Sources

- [github.com/Avunu/cloudflare-email-relay](https://github.com/Avunu/cloudflare-email-relay)
- [github.com/Avunu/mail-addons/tree/18.0/mail_cloudflare](https://github.com/Avunu/mail-addons/tree/18.0/mail_cloudflare)
- [github.com/Avunu/cloudflare_email_delivery](https://github.com/Avunu/cloudflare_email_delivery)

Need help with business email?

Our notes can take you a long way, but sometimes you'd rather have someone who's done it before.

[Managed infrastructure](/services/infrastructure/)

[← PreviousOverview](/kb/email/)[Next →Email without SMTP for business systems](/kb/email/email-without-smtp-for-business-systems/)

CC0This article is in the public domain ([CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/)), code samples included. Use it however helps you.

On this page

- [How the relay behaves](#how-the-relay-behaves)
- [Prerequisites](#prerequisites)
- [Layout of a deployment](#layout-of-a-deployment)
- [The wrapper](#the-wrapper)
- [The Wrangler config](#the-wrangler-config)
- [Create the bucket and set the ops token](#create-the-bucket-and-set-the-ops-token)
- [Define a tenant](#define-a-tenant)
- [The tenant table](#the-tenant-table)
- [The tenant secret](#the-tenant-secret)
- [Deploy](#deploy)
- [Route mail to the Worker](#route-mail-to-the-worker)
- [Use the ops API](#use-the-ops-api)
- [Verify a test message end to end](#verify-a-test-message-end-to-end)
- [Reading the result](#reading-the-result)
- [Test locally first](#test-locally-first)
- [Related documents](#related-documents)

[Back to top↑](#top)

Services

- [ERP implementation](/services/erp/)
- [Odoo](/services/erp/odoo/)
- [ERPNext](/services/erp/erpnext/)
- [Custom software](/services/custom-software/)
- [Devices & IoT](/services/devices-iot/)
- [Websites](/services/websites/)
- [Infrastructure](/services/infrastructure/)

Resources

- [Our work](/work/)
- [Open source](/open-source/)
- [Knowledge base](/kb/)
- [Insights](/insights/)

Company

- [About](/about/)
- [Team](/about/team/)
- [Partners](/partners/)
- [Contact](/contact/)

Clients

- [Project portal](https://erp.avunu.net/projects)
- [Invoices](https://erp.avunu.net/)
- [Support](https://erp.avunu.net/)

[![Avunu](/brand/avunu-logo-light.svg)](/)[\<av-icon data-jx-static>\<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" stroke="none" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\<path d="M20.400 20.500h-3.600v-5.600c0-1.300 0-3-1.800-3s-2.100 1.400-2.100 2.900v5.700H9.400V9h3.400v1.600c.5-.9 1.600-1.900 3.400-1.900 3.600 0 4.300 2.400 4.300 5.500v6.300zM5.300 7.400a2.100 2.100 0 1 1 0-4.100 2.100 2.100 0 0 1 0 4.100zm1.800 13.100H3.600V9h3.500v11.500zM22.200 0H1.800C.8 0 0 .8 0 1.700v20.600c0 .9.800 1.700 1.800 1.700h20.400c1 0 1.800-.8 1.800-1.700V1.700C24 .8 23.200 0 22.200 0z">\</path>\</svg>\</av-icon>](https://www.linkedin.com/company/avunu)[\<av-icon data-jx-static>\<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" stroke="none" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\<path d="M12 .3a12 12 0 0 0-3.8 23.4c.6.1.8-.3.8-.6v-2c-3.3.7-4-1.6-4-1.6-.6-1.4-1.4-1.8-1.4-1.8-1-.7.1-.7.1-.7 1.2.1 1.8 1.2 1.8 1.2 1 1.8 2.8 1.3 3.5 1 .1-.8.4-1.3.7-1.6-2.7-.3-5.5-1.3-5.5-5.9 0-1.3.5-2.4 1.2-3.2-.1-.3-.5-1.5.1-3.2 0 0 1-.3 3.3 1.2a11.500 11.500 0 0 1 6 0c2.300-1.500 3.300-1.200 3.300-1.200.6 1.700.2 2.900.1 3.200.8.8 1.200 1.900 1.200 3.200 0 4.600-2.800 5.600-5.500 5.900.4.400.8 1.100.8 2.200v3.300c0 .3.2.7.8.6A12 12 0 0 0 12 .3">\</path>\</svg>\</av-icon>](https://github.com/Avunu)[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

Avunu LLC · 948 East Philadelphia Street, York, PA 17403 · (717) 814-8540Knowledge base articles are in the public domain[Privacy](/privacy/)[Terms](/terms/)
