Email Workers now support threaded replies
Email Workers can now reply to incoming emails while maintaining thread continuity, enabling better AI agent and automation workflows. This requires valid DMARC, one reply per event, matching sender/recipient domains, and a 100-reference limit to prevent loops.
We’re removing some of the restrictions in Email Routing so that AI Agents and task automation can better handle email workflows, including how Workers can reply to incoming emails.
It's now possible to keep a threaded email conversation with an Email Worker script as long as:
- The incoming email has to have valid DMARC ↗.
- The email can only be replied to once in the same
EmailMessageevent. - The recipient in the reply must match the incoming sender.
- The outgoing sender domain must match the same domain that received the email.
- Every time an email passes through Email Routing or another MTA, an entry is added to the
Referenceslist. We stop accepting replies to emails with more than 100Referencesentries to prevent abuse or accidental loops.
Here's an example of a Worker responding to Emails using a Workers AI model:
AI model responding to emailstsimport PostalMime from "postal-mime";
import { createMimeMessage } from "mimetext";
import { EmailMessage } from "cloudflare:email";
export default {
async email(message, env, ctx) {
const email = await PostalMime.parse(message.raw);
const res = await env.AI.run("@cf/meta/llama-2-7b-chat-fp16", {
messages: [
{
role: "user",
content: email.text ?? "",
},
],
});
// message-id is generated by mimetext
const response = createMimeMessage();
response.setHeader("In-Reply-To", message.headers.get("Message-ID")!);
response.setSender("agent@example.com");
response.setRecipient(message.from);
response.setSubject("Llama response");
response.addMessage({
contentType: "text/plain",
data:
res instanceof ReadableStream
? await new Response(res).text()
: res.response!,
});
const replyMessage = new EmailMessage(
"<email>",
message.from,
response.asRaw(),
);
await message.reply(replyMessage);
},
} satisfies ExportedHandler<Env>;
See Reply to emails from Workers for more information.
Source: original entry ↗
More from Cloudflare
Follow Cloudflare to get its new changes in your feed and email digest.
Cloudflare One Client for macOS 2026.8.2100.0
GA release for macOS Cloudflare One Client with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster connects with lower memory use, and numerous reliability fixes across DNS, reauthentication, and client stability.
Cloudflare One Client for Windows 2026.8.2100.0
This GA release improves split tunnel reliability, adds support for non-RFC 1918 local networks, optimizes connection performance with faster reconnections and lower memory usage, and includes numerous bug fixes for DNS, registration, and network handling. The client now features a service recovery mechanism that automatically restarts on system unlock and better handles large hosts files without blocking traffic.
Cloudflare One Client for Linux 2026.8.2100.0
New GA release for Linux with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster tunnel reconnections, and lower memory usage. Includes numerous stability and reliability fixes for DNS, reconnection behavior, and crash issues.