Envello
Tutorial

Sending email from a Cloudflare Worker

Envello Team·2026-07-17·4 min read

Cloudflare Workers run on a V8 isolate, not Node.js, so a Node-specific SDK isn't guaranteed to work without adjustment even if the package itself doesn't obviously depend on Node APIs. The safe, dependency-free path is the Worker's built-in fetch, which is exactly what any SDK would be calling under the hood anyway.

The whole integration

  • const response = await fetch('https://api.envello.dev/emails', { method: 'POST', headers: { Authorization: `Bearer ${env.ENVELLO_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ from: 'Acme <[email protected]>', to: recipient, subject: 'Welcome!', html }) })
  • Store the API key as a Worker secret (wrangler secret put ENVELLO_API_KEY), never hardcoded in the Worker script
  • Check response.ok before assuming the send succeeded

Rendering the HTML body

Workers don't have a templating engine built in, so the html field is usually either a plain template string with interpolated values for simple emails, or output from a lightweight templating approach that runs in the Workers runtime. Avoid anything that assumes Node-specific APIs (the file system, most npm packages built for a Node environment) since the Workers runtime doesn't have them.

Where this typically gets called from

A Worker handling a form submission, a webhook from another service, or a scheduled Cron Trigger are the common entry points for a transactional send in this environment. The fetch call above works identically regardless of what triggered the Worker, since it's just an outbound HTTP request like any other the Worker might make.

Envello

EU-hosted transactional email, done right by default.