Auto-reply with a Cloudflare Email Worker
Cloudflare Email Routing has no auto-reply setting, but a short Email Worker can answer each sender with message.reply(). Here is the code and its rules.
On this page · 5 sections
What it can do
A routing rule on its own forwards or drops mail. To answer automatically (thanks, we got it or I'm away until Monday), send the address to an Email Worker and call message.reply() in it. The reply goes to the person who wrote, and Cloudflare threads it under their message. [1]
Set it up
- In the Cloudflare dashboard, go to Workers & Pages, create a Worker, and replace its code with the example below, using your own inbox.
- Open your domain, then Email > Email Routing > Routing rules. Edit the address (for example hello@yourdomain.com), set the action to Send to a Worker, and pick the Worker.
- Send a test message from another account. It should reach your inbox, and the sender should get the reply.
export default {
async email(message, env, ctx) {
const subject = message.headers.get("Subject") ?? "";
// A verified destination address.
await message.forward("you@gmail.com");
try {
await message.reply({
from: message.to,
subject: `Re: ${subject}`,
text: "Thanks, we got your message.",
});
} catch (e) {
console.log("No auto-reply:", e.code ?? e.message);
}
},
};The reply builder takes from, subject, text or html, and optionally replyTo, attachments and headers. It has no to, cc or bcc: the reply always goes to the sender. [1]
The rules a reply must follow
If any of these isn't met, reply() throws an error instead of sending. [1]
- The incoming message must have a valid DMARC result. Mail that fails DMARC can't be answered this way.
- One reply per message. A failed
reply()also counts as the one reply. - From your own domain. The reply's sender must be on the domain that received the mail.
message.tois the simplest choice. - No reply loops. A message with more than 100 entries in its References header is refused.
- It needs a Message-ID. Without one the reply can't be threaded, and the error code is
E_FIELD_MISSING.
To forward to two or more inboxes from the same Worker, see Forward one Cloudflare email address to several inboxes. Forwarding only works to verified destination addresses. [1] If mail doesn't arrive at all, start with Cloudflare Email Routing not working.
Auto-replies in Ayoh
Ayoh runs in your own Cloudflare account and its Worker already receives your domain's mail, so you don't write one. When a person writes to you, it drafts a reply, and you send it, edit it or leave it. See AI in your mail. Setup is in Getting started.
Sources
Read November 18, 2026.
- [1] Cloudflare, Workers API for Email Routing (opens in a new tab), updated November 17, 2026:
reply()and its builder, the reply requirements, error codes, andforward()to verified destination addresses.