sendsend.email

Send email with Cloudflare Workers

A server-side call to the SendSend API from your Cloudflare Workers app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Store the key as a secret: run `wrangler secret put SENDSEND_API_KEY`. Never put it in wrangler.toml.
  3. Add this to src/index.ts:
export default {
  async fetch(request: Request, env: { SENDSEND_API_KEY: string }): Promise<Response> {
    const { to } = await request.json<{ to: string }>();
    return fetch('https://api.sendsend.email/v1/emails', {
      method: 'POST',
      headers: { Authorization: `Bearer ${env.SENDSEND_API_KEY}`, 'Content-Type': 'application/json', 'Idempotency-Key': crypto.randomUUID() },
      body: JSON.stringify({ from: 'Acme <hello@mail.acme.com>', to: [to], subject: 'Hello from a Worker', html: '<p>It works!</p>' }),
    });
  },
};

Good to know