Add MessageBuilder support for Email Sending API in local mode#11942
Merged
Add MessageBuilder support for Email Sending API in local mode#11942
MessageBuilder support for Email Sending API in local mode#11942Conversation
… mode Implements support for the simplified MessageBuilder interface in Miniflare's Email Sending API binding. This provides a developer-friendly alternative to manually constructing MIME messages with the EmailMessage API. Key changes: - Add TypeScript types for MessageBuilder API (types.ts) - Implement send() overload accepting MessageBuilder alongside EmailMessage - Store email content (text, HTML, attachments) to viewable temp files - Extract common storeTempFile() helper to reduce duplication - Add comprehensive test coverage (12 new tests) In local mode, content is saved to files that developers can open in their editor/browser for inspection, with file paths logged to the console.
🦋 Changeset detectedLatest commit: 5dac37e The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
MessageBuilder support for Email Sending API in local mode
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
penalosa
commented
Jan 15, 2026
|
|
||
| Add support for Email Sending API's MessageBuilder interface in local mode | ||
|
|
||
| Miniflare now supports the simplified MessageBuilder interface for sending emails, alongside the existing EmailMessage (raw MIME) support. This matches the API available in production Workers. |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| Miniflare now supports the simplified MessageBuilder interface for sending emails, alongside the existing EmailMessage (raw MIME) support. This matches the API available in production Workers. | |
| Miniflare now supports the simplified MessageBuilder interface for sending emails, alongside the existing `EmailMessage` support. |
| await env.EMAIL.send({ | ||
| from: { name: "Alice", email: "alice@example.com" }, | ||
| to: ["bob@example.com"], | ||
| subject: "Hello from Miniflare", |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| subject: "Hello from Miniflare", | |
| subject: "Hello", |
| }); | ||
| ``` | ||
|
|
||
| In local mode, email content (text, HTML, attachments) is stored to temporary files that you can open in your editor or browser for inspection. File paths are logged to the console when emails are sent. |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| In local mode, email content (text, HTML, attachments) is stored to temporary files that you can open in your editor or browser for inspection. File paths are logged to the console when emails are sent. |
| } else if (content instanceof ArrayBuffer) { | ||
| body = new Uint8Array(content); | ||
| } else { | ||
| // ArrayBufferView |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| // ArrayBufferView |
- Simplify changeset description - Shorten example subject to 'Hello' - Remove trailing newline in changeset - Remove extra blank line in send_email.worker.ts
Adds comprehensive manual testing examples for the MessageBuilder API: - /send-simple: Basic text-only email - /send-html: Email with text and HTML content - /send-attachment: Single text attachment - /send-multi-attachment: Multiple attachment types (text, JSON, binary) - /send-complex: Multiple recipients (to/cc/bcc) - /test-bindings: Test all three binding types Also includes: - README with complete usage instructions - Documentation of expected console output - Notes about type assertions (types not yet in @cloudflare/workers-types) Tested locally - all routes work correctly.
The validateMessageBuilder function was passing EmailAddress objects
(with { name, email } structure) directly to validateRecipients, which
expected strings. This caused the error 'email to [object Object] not allowed'.
Fix: Extract email addresses from EmailAddress objects before validation
using the existing extractEmailAddress helper.
Tested with fixture routes that use EmailAddress objects:
- /send-simple (named sender)
- /send-complex (multiple recipients with names)
All tests pass.
The MessageBuilder snapshot test was failing on Windows because the regex only matched Unix-style paths (/...). Updated the regex to also match Windows paths (C:\...) while still normalizing both to the same format. Regex now matches: - Unix: /var/folders/.../email-text/uuid.txt - Windows: C:\Users\...\email-text\uuid.txt Both normalize to: /email-text/[FILE].txt
The proxy server previously only handled EmailMessage objects by reconstructing them from the serialized 'EmailMessage::raw' property. This fix adds detection for MessageBuilder objects and passes them through directly since they're already plain serializable objects. Changes: - Check if the argument has 'EmailMessage::raw' property to distinguish EmailMessage from MessageBuilder - EmailMessage: Reconstruct with EmailMessage constructor (existing behavior) - MessageBuilder: Pass through directly as plain object (new behavior) Both APIs now work correctly in remote mode via wrangler dev --remote.
Bumps the workerd-and-workers-types group with 2 updates: [workerd](https://github.com/cloudflare/workerd) and [@cloudflare/workers-types](https://github.com/cloudflare/workerd). Updates `workerd` from 1.20260115.0 to 1.20260116.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](cloudflare/workerd@v1.20260115.0...v1.20260116.0) Updates `@cloudflare/workers-types` from 4.20260115.0 to 4.20260116.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/commits) --- updated-dependencies: - dependency-name: workerd dependency-version: 1.20260116.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types - dependency-name: "@cloudflare/workers-types" dependency-version: 4.20260116.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types ... Signed-off-by: dependabot[bot] <support@github.com>
The following dependency versions have been updated: | Dependency | From | To | | ---------- | ------------ | ------------ | | workerd | 1.20260115.0 | 1.20260116.0 |
LuisDuarte1
approved these changes
Jan 19, 2026
Contributor
LuisDuarte1
left a comment
There was a problem hiding this comment.
thank you for the help 🫶, lgtm!
vicb
reviewed
Jan 19, 2026
emily-shen
reviewed
Jan 19, 2026
emily-shen
approved these changes
Jan 19, 2026
Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>
Merged
Skye-31
added a commit
to Skye-31/workerd
that referenced
this pull request
Jan 19, 2026
Now that this is supported locally cloudflare/workers-sdk#11942 and ungated in production, these types are ready to update.
Skye-31
added a commit
to Skye-31/workerd
that referenced
this pull request
Jan 19, 2026
Now that this is supported locally (ref: cloudflare/workers-sdk#11942) and ungated in production, these types are ready to be updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements support for the simplified
MessageBuilderinterface in Miniflare's Email Sending API binding. This provides a developer-friendly alternative to manually constructing MIME messages with the EmailMessage API.Key changes:
In local mode, content is saved to files that developers can open in their editor/browser for inspection, with file paths logged to the console.
A picture of a cute animal (not mandatory, but encouraged)