Send email from a Cloudflare Worker.
A Worker sends through Notix with the fetch it already has; no dependency is needed for the send. Store the key with wrangler secret put, read it from env, and add the nodejs_compat flag only if you import notix-js, whose webhook verifier uses Node's crypto module.
Send an email from Cloudflare Workers.
export default {
async fetch(request: Request, env: { NOTIX_API_KEY: string }): Promise<Response> {
const { to } = await request.json<{ to: string }>();
const response = await fetch("https://app.usenotix.dev/api/v1/emails", {
method: "POST",
headers: { Authorization: `Bearer ${env.NOTIX_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ from: "Acme <receipts@acme.com>", to, subject: "Your receipt", html: "<p>Thanks.</p>" }),
});
return new Response(await response.text(), { status: response.status });
},
};
The from address must be on a domain you have verified in Notix. Step by step: the cURL quickstart and the longer guide to sending email from Cloudflare Workers.
The key as a Worker secret.
Run wrangler secret put NOTIX_API_KEY and read it from env inside the handler. A secret is encrypted and never shown in the dashboard or in wrangler.toml.
If the Worker imports notix-js, add compatibility_flags = ["nodejs_compat"] to wrangler.toml: the package imports node:crypto when it loads. A fetch-only Worker does not need it.
Questions, answered.
Why does notix-js need nodejs_compat on Workers?
What if the same request runs twice?
Why is my send refused with a from-address error?
Send your first email in five minutes.
Verify a domain, copy an API key, make one call. The free plan does not ask for a card.