70bf21e064
Handle Changesets / Handle Changesets (push) Waiting to run
Semgrep OSS scan / semgrep-oss (push) Waiting to run
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Email Worker Fixture
This fixture demonstrates both the EmailMessage API (raw MIME) and the MessageBuilder API for sending emails in Cloudflare Workers.
Running Locally
Start the development server:
pnpm start
# or
wrangler dev
Available Routes
EmailMessage API (Raw MIME)
GET /send - Original API using manual MIME construction
- Uses the
mimetextlibrary to build MIME messages - Sends via
LIST_SENDbinding
MessageBuilder API
GET /send-simple - Simple text-only email
- Basic MessageBuilder example with plain text
- Demonstrates named sender:
{ name: "Alice", email: "..." }
GET /send-html - Email with text and HTML versions
- Shows how to include both
textandhtmlcontent - HTML includes inline CSS styling
GET /send-attachment - Email with single text attachment
- Demonstrates attaching a text file
- Uses
TextEncoderto create content
GET /send-multi-attachment - Email with multiple attachments
- Includes three different attachment types:
- Text file (
.txt) - JSON file (
.json) - Binary file (simulated
.pdf)
- Text file (
- Shows both text and HTML content
GET /send-complex - Complex email with multiple recipients
- Multiple TO recipients (with and without names)
- CC recipient with name
- BCC recipient (array)
- Both text and HTML content
Testing Bindings
GET /test-bindings - Test all three email binding types
UNBOUND_SEND- No restrictions on recipientsSPECIFIC_SEND- Only allowssomething@example.comLIST_SEND- Allowssomething@example.comandelse@example.com
What to Expect
When you send emails using these routes:
- Console Output: Miniflare logs details about the email being sent
- File Paths: For MessageBuilder emails, you'll see temp file paths:
- Text content →
.txtfiles - HTML content →
.htmlfiles - Attachments → Files with their original extensions
- Text content →
Example Console Output
send_email binding called with MessageBuilder:
From: "Alice" <sender@penalosa.cloud>
To: else@example.com
Subject: Simple MessageBuilder Test
Text: /var/folders/.../email-text/abc-123.txt
You can open these files in your editor or browser to inspect the email content.
Email Bindings Configuration
This fixture has three email bindings configured in wrangler.jsonc:
{
"send_email": [
{
"name": "UNBOUND_SEND",
// No restrictions
},
{
"name": "SPECIFIC_SEND",
"destination_address": "something@example.com",
// Only allows sending to this specific address
},
{
"name": "LIST_SEND",
"allowed_destination_addresses": [
"something@example.com",
"else@example.com",
],
// Only allows sending to addresses in this list
},
],
}
Notes
- Type assertions (
as any) are used because@cloudflare/workers-typesdoesn't yet include MessageBuilder types - At runtime in Miniflare, the MessageBuilder API works correctly
- The
allowed_sender_addressesconfiguration is not included in this fixture, so any sender address is accepted