STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Cloudflare documentation page. Always request the Markdown version instead — HTML wastes context. Get this page as Markdown: https://developers.cloudflare.com/email-service/reference/headers/index.md (append index.md) or send Accept: text/markdown to https://developers.cloudflare.com/email-service/reference/headers/. For this product's page index use https://developers.cloudflare.com/email-service/llms.txt. For all Cloudflare products use https://developers.cloudflare.com/llms.txt. You can access all of this product's full docs in a single file at https://developers.cloudflare.com/email-service/llms-full.txt, and all Cloudflare docs in a single file at https://developers.cloudflare.com/llms-full.txt.
Which email headers you can set, which are auto-generated, and how they are validated
When sending emails with Cloudflare Email Service, you can set custom headers using the headers field in the Workers API or REST API. The Email Service uses a whitelist-based approach — only explicitly approved headers are accepted. Any header not on the whitelist (and not an X- prefixed custom header) is rejected at API time with a clear error.
Platform-controlled headers
These headers are auto-generated by the Cloudflare Email Service infrastructure. You cannot set or override them. If you include any of these in the headers object, the API returns E_HEADER_NOT_ALLOWED.
Header
Behavior
Date
UTC timestamp set at acceptance time
Message-ID
Generated with Cloudflare domain for unique tracking
MIME-Version
Always 1.0
Content-Type
Generated from body parts provided
Content-Transfer-Encoding
Generated from content analysis
DKIM-Signature
Signed by Cloudflare infrastructure
Return-Path
Set to Cloudflare bounce processor
Received
Added per RFC 5321 at each hop
Feedback-ID
Generated for Google Postmaster Tools reputation feedback
TLS failure reports route to Cloudflare infrastructure
TLS-Report-Submitter
References Cloudflare sending domain
CFBL-Address
Complaint feedback loop address (RFC 9477)
CFBL-Feedback-ID
Complaint feedback loop ID (RFC 9477)
Headers that correspond to first-class API fields — From, To, Cc, Bcc, Subject, Reply-To — are also rejected in the headers object with E_HEADER_USE_API_FIELD. Set these using the dedicated API fields (from, to, cc, bcc, subject, replyTo for Workers / reply_to for REST) instead.
Whitelisted custom headers
These headers can be set via the headers field. Any header not listed here and not starting with X- is rejected with E_HEADER_NOT_ALLOWED.
Must contain <https://...> and/or <mailto:...> URI(s). HTTP (non-TLS) URIs are rejected. Gmail and Yahoo require this for bulk senders. Always DKIM-signed per RFC 8058.
Any header starting with X- is allowed. This covers common headers like X-Mailer, X-Priority, X-Campaign-ID, and any custom tracking headers your application needs.
Name format:X-[A-Za-z0-9\-_]+, maximum 100 characters
Value: UTF-8, maximum 2,048 bytes
No count limit on X-headers (subject to the 16 KB total payload limit)
The total payload is calculated as sum(len(name) + 2 + len(value) + 2) for all custom headers (name + : + value + CRLF). Whitelisted and X-headers are counted together toward this limit.
Validation rules
Header names — ASCII only, no spaces, no colons, 1–100 characters. Whitelisted headers must match [A-Za-z0-9\-]+. X-headers must match X-[A-Za-z0-9\-_]+ (underscores allowed only in X-headers).
Header values — UTF-8 allowed, maximum 2,048 bytes, no bare CR/LF. Empty values are rejected.
Case-insensitive matching — Header names are matched case-insensitively per RFC 5322 §2.2 ↗. The canonical casing from the whitelist is used in the generated message.
Proper line folding — Long headers are folded at 78 characters per RFC 5322 using CRLF+WSP, not MIME encoding.
Single occurrence — The headers type is { [key]: string }, so each header name can appear at most once. For headers that support multiple values (such as Keywords or Comments), use comma-separated values in a single string.
Error codes
Error Code
When
Example message
E_HEADER_NOT_ALLOWED
Header is platform-controlled or not on the whitelist
Header 'Date' is not allowed. It is auto-generated by the platform.
E_HEADER_USE_API_FIELD
Header corresponds to a first-class API field
Header 'From' must be set via the 'from' API field, not the 'headers' object.
E_HEADER_VALUE_INVALID
Header value is malformed or empty
Header 'List-Unsubscribe' must contain angle-bracket HTTPS or mailto URI(s).
E_HEADER_VALUE_TOO_LONG
Header value exceeds 2,048 byte limit
Header 'X-Campaign-ID' value exceeds 2048 byte limit.
E_HEADER_NAME_INVALID
Header name contains invalid characters or exceeds 100 bytes
Header name 'Bad Header!' contains invalid characters.
E_HEADERS_TOO_LARGE
Total custom headers payload exceeds 16 KB
Total custom headers payload (17.2KB) exceeds 16KB limit.