Test email sending locally
Test email sending Workers locally using wrangler dev with simulated email delivery
Last updated Oct 15, 2026
Test email sending functionality locally using wrangler dev to simulate email delivery and verify your sending logic before deploying.
Note
If you are using the REST API instead of Workers, you can test by sending requests directly with curl or any HTTP client without a local development server. The rest of this page covers the Workers local development flow.
Prerequisites
- Sign up for a Cloudflare account ↗︎.
- Install
Node.js↗︎.
<details>
<summary>
Node.js version manager
</summary>
Use <a href="https://viteplus.dev/guide/env">Vite+ (<code>vp env</code>) ↗︎</a> to install and manage Node.js versions.
For supported Node.js versions, refer to the <a href="https://developers.cloudflare.com/workers/wrangler/install-and-update/#install-wrangler">Wrangler system requirements</a>.
</details>
Configuration
Configure your Wrangler file with the email binding:
{
"name": "email-sending-worker",
// Set this to today's date
"compatibility_date": "2026-10-27",
"send_email": [{ "name": "EMAIL" }],
}
name = "email-sending-worker"
# Set this to today's date
compatibility_date = "2026-10-27"
[[send_email]]
name = "EMAIL"
Remote bindings (recommended)
Use remote bindings to develop with Email Service locally. With remote bindings, your Worker runs locally but sends real emails through Email Service.
By default, wrangler dev simulates the email binding locally. It logs emails to the console but does not send them.
Set remote: true on the email binding in your Wrangler configuration:
{
"name": "email-sending-worker",
// Set this to today's date
"compatibility_date": "2026-10-27",
"send_email": [
{
"name": "EMAIL",
"remote": true,
},
],
}
name = "email-sending-worker"
# Set this to today's date
compatibility_date = "2026-10-27"
[[send_email]]
name = "EMAIL"
remote = true
Then run wrangler dev as usual. Calls to env.EMAIL.send() send actual emails through Email Service while your Worker code runs locally.
Caution
Remote bindings send real emails to real recipients. Use test email addresses to avoid sending unintended emails during development.
Local simulation
When running wrangler dev without remote bindings, the email binding is simulated locally. Emails are not sent. Instead, the email content is logged to the console and saved to local files for inspection.
Basic sending worker
export default {
async fetch(request, env, ctx) {
if (request.method !== "POST") {
return new Response("Method not allowed", { status: 405 });
}
try {
const emailData = await request.json();
console.log("Sending email:", {
to: emailData.to,
from: emailData.from,
subject: emailData.subject,
});
const response = await env.EMAIL.send(emailData);
return new Response(
JSON.stringify({
success: true,
id: response.messageId,
}),
{
headers: { "Content-Type": "application/json" },
},
);
} catch (error) {
return new Response(
JSON.stringify({
success: false,
error: error.message,
}),
{
status: 500,
headers: { "Content-Type": "application/json" },
},
);
}
},
};
Test locally
Start your development server:
npx wrangler dev
Send a test email:
curl -X POST http://localhost:8787/ \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"from": "sender@yourdomain.com",
"subject": "Test Email",
"html": "<h1>Hello from Wrangler!</h1>",
"text": "Hello from Wrangler!"
}'
Wrangler shows output like:
[wrangler:info] send_email binding called with MessageBuilder:
From: sender@yourdomain.com
To: recipient@example.com
Subject: Test Email
Text: /tmp/miniflare-.../files/email-text/<message-id>.txt
The email content (text and HTML) is saved to local files that you can inspect to verify your email structure before deploying.
Known limitations
Binary attachments
Local development simulates the send_email binding locally, but ArrayBuffer values in attachment content cannot be serialized by the local simulator. If you pass an ArrayBuffer (for example, for image or PDF attachments), you receive an error like:
Cannot serialize value: [object ArrayBuffer]
Workaround: Use string content for text-based attachments during local development. To test binary attachments (images, PDFs), deploy your Worker with npx wrangler deploy and test against the deployed version.
This limitation only affects local development — ArrayBuffer content works correctly on deployed Workers.
Next steps
- Deploy your sending worker: Send emails get started
- Explore advanced patterns: Email sending examples
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/email-service/observability/local-development/sending/#page","headline":"Test email sending locally","description":"Test Email Service sending Workers locally with simulated delivery.","url":"https://developers.cloudflare.com/email-service/observability/local-development/sending/","inLanguage":"en","image":"https://developers.cloudflare.com/email-service/observability/local-development/sending/og.png?v=76c071adeb4a172d","dateModified":"2026-10-15","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Email Service activity statuses, authentication details, and message fields. title: Activity log image: https://developers.cloudflare.com/email-service/observability/logs/og.png?v=7322ea94b0a5a48d
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/email-service/llms.txt
Use this file to discover all available pages before exploring further.
Docs