Skip to content

fix(email-service): Workers API documents EmailAddress.name as optional, but the binding requires it #35025

Closed

Description

@coygeek

Existing documentation URL(s)

What changes are you suggesting?

The Email Sending Workers API page declares interface EmailAddress { email: string; name?: string; }, and the 2026-05-28 changelog says to pass "an object with email and an optional name field" for to, cc, bcc, replyTo, or from. The email binding source migrated from Cloudflare's internal repository requires name and, per its own comment, throws a synchronous TypeError when it is missing; the published @cloudflare/workers-types also declare name: string as required. According to that source, code written from the docs, such as to: { email: "[email protected]" }, throws at the send() call in production. Local wrangler dev accepts the same call, so the mismatch would not show up until deployment. The REST API is not affected: its EmailAddressObject requires only address and makes name nullable.

Additional information

Runtime or environment

cloudflare/cloudflare-docs production at 2a4bfc47c14e4943329abbb2f741b897c7184071 and the published pages as of 2026-11-08. Runtime source: src/workerd/api/email.h in open, unmerged cloudflare/workerd pull request #8222 at head b3267af57e368a5c22e5a5af86fd42bb66d5fdd4, whose description reads "Migrating from the internal repo ... moving into workerd as-is is the first step". Local run: wrangler 4.158.0 (latest on npm on 2026-11-08) with its bundled workerd 1.20261104.1 and miniflare 5.20261104.0-beta, Node.js v26.12.1, compatibility_date 2026-11-01. Types: @cloudflare/workers-types 5.20261108.1 (latest on npm on 2026-11-08). REST schema: cloudflare/api-schemas at 650bd71c22db3b938a4611bf4cc5afd896b400b7.

Steps to reproduce

  1. Read the send() interface on the Workers API page (src/content/docs/email-service/api/send-emails/workers-api.mdx lines 43-46) and the changelog entry (src/content/changelog/email-service/2026-05-28-named-email-recipients.mdx line 11).
  2. Following them, call the binding with a named-address object that omits name: await env.EMAIL.send({ from: "[email protected]", to: { email: "[email protected]" }, subject: "Hi", text: "Hi" }).
  3. Compare with the runtime declaration of EmailAddress in src/workerd/api/email.h (pull request [ZT] Add egress policies #8222) and with interface EmailAddress in @cloudflare/workers-types.

Step 2 was run only under local wrangler dev, not against production, because the investigating account has no Email Sending entitlement. The production failure is inferred from the runtime source.

Expected behavior

The Workers API reference and changelog should describe the binding's actual input contract: for the Workers binding, a named-address object needs both email and name, and a bare string is the form for an address without a display name. If omitting name is intended to be supported, the docs and the runtime would need to agree on that instead; today they do not.

Actual behavior

The docs declare name?: string and call name optional. The runtime source declares:

// `name` is intentionally not wrapped in `jsg::Optional`: callers omitting `name`
// (e.g. `{ email: "[email protected]" }`) must receive a synchronous TypeError, not a silent default.
struct EmailAddress {
  jsg::NonCoercible<kj::String> name;
  jsg::NonCoercible<kj::String> email;

  JSG_STRUCT(name, email)
};

@cloudflare/workers-types declares interface EmailAddress { name: string; email: string; }. Under local wrangler dev, step 2 did not throw: env.EMAIL.send() with to: { email: "[email protected]" } resolved with a messageId, so the local simulator accepts the documented shape that the runtime source rejects. The same local send also logged [wrangler:warn] Failed to capture sent email for the Local Explorer; the email was still sent. and Failed to persist sent email: TypeError: Cannot read properties of undefined (reading 'replace'), so local tooling also fails on an address object without name. In cloudflare/api-schemas, email-sending_EmailAddressObject lists only address as required and describes name as "Optional; set to null or leave it unset", so the REST API page's examples are consistent with the REST contract.

Evidence

  • Expected source: src/content/docs/email-service/api/send-emails/workers-api.mdx lines 43-46 and src/content/changelog/email-service/2026-05-28-named-email-recipients.mdx line 11 state the documented contract under test.
  • Failure source: src/workerd/api/email.h lines 29-35 in cloudflare/workerd pull request [ZT] Add egress policies #8222, which requires name and states that omitting it throws a synchronous TypeError; interface EmailAddress in @cloudflare/workers-types agrees.
  • Evidence provenance: static
  • Local verification: not-reproduced
  • Reproduction completeness: incomplete
  • Missing fact: The observed result of step 2 against the production send_email binding; the investigating account cannot send email.

The local rerun did not reproduce the failure, because Miniflare accepts an address object without name. Production was not tested. The production conclusion rests on pull request #8222 reflecting the internal implementation, as its description states, and on JSG_STRUCT unwrapping throwing for a missing non-optional field; the pull request is unmerged, so it is strong but indirect evidence of deployed behavior.

Restoration check

Failing: the Workers API reference shows name?: string and the changelog calls name optional while, per the runtime source, the binding throws TypeError for { email } without name. Passing: the Workers binding reference and the changelog describe name as required in an address object (or the binding accepts a missing name and the docs keep calling it optional), and the REST API pages continue to describe name as optional for REST.

Triage assessment

  • Impact level: P2
  • Assessment status: provisional
  • Impact basis: Per the runtime source, following the documented shape makes send() throw in production, so the email is not sent. Local development accepts the same code, so the failure would first appear after deployment. It affects only callers who pass an address object without name. Production behavior is inferred from runtime source, not observed.
  • Workaround status: available
  • Workaround basis: Passing the address as a plain string, or including name in the object, uses forms the docs already show and the runtime accepts.

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions