-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add MessageBuilder support for Email Sending API in local mode
#11942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… 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: 7b8629b 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: |
|
|
||
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: "[email protected]" }, | ||
| to: ["[email protected]"], | ||
| subject: "Hello from Miniflare", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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.
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)