Test email sending functionality locally using wrangler dev to simulate email delivery and verify your sending logic before deploying.
- Sign up for a Cloudflare account ↗︎.
- Install
Node.js↗︎.
Node.js version manager
Use Vite+ (vp env) ↗︎ to install and manage Node.js versions.
For supported Node.js versions, refer to the Wrangler system requirements.
Configure your Wrangler file with the email binding:
{
"name": "email-sending-worker",
// Set this to today's date
"compatibility_date": "2026-12-01",
"send_email": [{ "name": "EMAIL" }],
}name = "email-sending-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
[[send_email]]
name = "EMAIL"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-12-01",
"send_email": [
{
"name": "EMAIL",
"remote": true,
},
],
}name = "email-sending-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
[[send_email]]
name = "EMAIL"
remote = trueThen run wrangler dev as usual. Calls to env.EMAIL.send() send actual emails through Email Service while your Worker code runs locally.
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.
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" },
},
);
}
},
};Start your development server:
npx wrangler devSend 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>.txtWrangler saves the text, HTML, and attachments to files you can inspect before deploying. For binary attachments, pass an ArrayBuffer or a typed array as the attachment's content.
- Deploy your sending worker: Send emails get started
- Explore advanced patterns: Email sending examples