Repository navigation
Description
Existing documentation URL(s)
- https://developers.cloudflare.com/email-service/get-started/route-emails/#create-an-email-processing-worker
- https://developers.cloudflare.com/email-service/examples/email-routing/email-storage/
- https://developers.cloudflare.com/email-service/api/route-emails/email-handler/#reply-to-emails
What changes are you suggesting?
Explain that a threaded reply requires the incoming Message-ID, and update the examples to handle an otherwise valid incoming message without that header. The examples should complete the forwarding or storage and queue work they demonstrate, and continue to send a threaded reply for an eligible message with a valid ID.
Additional information
Summary
The reply branches in the routing examples call message.reply() even when the incoming message has no Message-ID. The Workers API documents E_FIELD_MISSING for this input. In examples that forward afterward, the documented exception prevents the forwarding call. In the queue example, the exception follows the storage write and enqueue.
Steps to reproduce
-
In Route emails, inspect the Worker created under Create an email processing Worker and its
support@branch. For the hosted case, consider an incoming support message with validFrom,Date, and body, a valid DMARC result, and noMessage-ID. Assume the forwarding inbox has been verified as the quickstart requires. This case was inspected in published source. -
Follow the branch. The
if (messageId)condition covers settingIn-Reply-To. The unconditionalawait message.reply(...)then precedes forwarding. Check the two storage examples and the simple, smart, and raw MIME reply examples on the Workers API page. -
For the local simulator comparison, create the following disposable Worker project. Save the first snippet as
worker.js. Its only action is to writeHANDLERto the console if invoked. Run the setup and start commands in a scratch directory using the Wrangler version listed below.
Local Worker fixture: worker.js
export default { async email() { console.log("HANDLER"); } };printf '{"name":"mail-routing-test","main":"worker.js","compatibility_date":"2026-12-03","send_metrics":false}\n' > wrangler.jsonc
wrangler dev --local --ip 127.0.0.1 --port 0 --config wrangler.jsonc- Save the following as
reproduce.pyand runpython3 reproduce.py PORT, wherePORTis the number printed by Wrangler. It uses only the Python standard library and posts two synthetic messages to the local endpoint, differing only in the presence ofMessage-ID. It prints each status and response body. Check whether Wrangler’s console logsHANDLERfor both requests or only the message with the header. This comparison exercises the local injection endpoint and logging fixture only.
Reproduction script: reproduce.py
from email.utils import formatdate
from sys import argv
from urllib.error import HTTPError
from urllib.request import Request, urlopen
port = int(argv[1])
endpoint = (
f"http://127.0.0.1:{port}/cdn-cgi/local/email"
"?from=sender%40example.net&to=support%40example.com"
)
date = formatdate(usegmt=True)
for has_message_id in (False, True):
headers = [
"From: sender@example.net",
"To: support@example.com",
"Subject: Test",
"Date: " + date,
]
if has_message_id:
headers.append("Message-ID: <control@example.net>")
raw = "\r\n".join([*headers, "", "Support request", ""]).encode()
request = Request(endpoint, data=raw, method="POST")
try:
result = urlopen(request)
except HTTPError as error:
result = error
with result:
print("Message-ID", has_message_id, result.status, result.read().decode())Expected behavior
The examples explain the threaded reply prerequisite. A message without an ID can still be forwarded or stored and queued where the example promises that behavior.
Actual behavior
In the hosted examples' source, the documented E_FIELD_MISSING exception would leave the forwarding call unreachable in the quickstart, first storage sample, and structured API examples' auto-reply branches. The raw MIME API example also calls reply() outside the ID check. The queue example stores and enqueues the email before attempting the reply, so a sender retry after that error can enqueue it again.
In the recorded local comparison, the message without an ID returned HTTP 400 with Email could not be parsed: invalid or no message id provided before the logging handler ran. Adding the header returned HTTP 200 and invoked the handler. The published local guide requires an ID for this endpoint. The hosted example behavior above comes from source and the Workers API contract.
Evidence
- Expected source: Workers API, Reply errors documents the exception. Handle redelivery explains that senders sometimes omit the ID, and RFC 5322 § 3.6.4 specifies a recommendation to include it. Test email routing locally documents the simulator requirement.
- Failure source: The three published examples linked above and their
productionsource insrc/content/docs/email-service/get-started/route-emails.mdx(reply before forwarding),src/content/docs/email-service/examples/email-routing/email-storage.mdx(reply before forwarding or after enqueue), andsrc/content/docs/email-service/api/route-emails/email-handler.mdx(structured and raw MIME replies). - Evidence provenance: static
- Local verification: not-reproduced
- Reproduction completeness: incomplete
- Missing fact: A hosted trace for the same otherwise valid, DMARC-passing message without
Message-ID, showing handler invocation and the reply exception before forwarding or after enqueue.
Restoration check
For an otherwise valid message without a Message-ID, examples that demonstrate forwarding still forward to their configured verified destination. The queue example stores and enqueues the message and completes the inbound handler without a reply error. Reply-only guidance states the prerequisite or demonstrates handling the missing header. A control with a valid ID still receives its threaded reply and retains the forwarding or queue behavior.
Runtime or environment
Published Cloudflare Developer Docs and production revision cd5bf82ac1d0d34fe13997eb15c6727b498cd926. The recorded local comparison used Wrangler 4.170.0, Miniflare 5.20261129.0-beta, and bundled workerd 1.20261129.1.
Triage assessment
- Impact level: P2
- Assessment status: supported
- Impact basis: An incoming message without this header can miss a documented forwarding action or trigger a reply error after storage and enqueue. Source establishes the path through the examples. Hosted frequency, delivery results, and retries were unmeasured.
- Workaround status: unverified
- Workaround basis: Forward-only examples avoid the reply prerequisite. Their applicability to the combined reply, forwarding, and storage workflows remains unverified.
References
- fix(email-service): raw MIME reply examples reject messages in existing threads #35756 — covered incomplete threading references when the incoming message already has a
Message-ID. - [Email Service] Fix Python email handler, raw MIME thread replies, and Worker routing quickstart #35842 — preserves the reference chain for those inputs and leaves the reply outside the
Message-IDcondition.
Activity