javascript · Jul 1, 2026
Cloudflare Email Worker
Cloudflare Email Worker
View on GitHubexport default {
async email(message, env, ctx) {
const subject = message.headers.get("subject") || "(no subject)";
await fetch("https://discord.com/api/webhooks/123/345", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
content: null,
embeds: [
{
title: "New email at [email protected]",
fields: [
{ name: "From", value: message.from || "Unknown", inline: false },
{ name: "To", value: message.to || "Unknown", inline: false },
{ name: "Subject", value: subject, inline: false },
],
timestamp: new Date().toISOString(),
},
],
}),
});
await message.forward("[email protected]");
},
};