Providers

Cloudflare

Send email through Cloudflare Email Service.
import { createClient } from '@nicogenz/emails-sdk';
import { cloudflare } from '@nicogenz/emails-sdk/cloudflare';

const email = createClient({
  provider: cloudflare({
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
    apiToken: process.env.CLOUDFLARE_API_TOKEN!,
  }),
});

Options

OptionTypeRequiredDescription
accountIdstringYesYour Cloudflare account ID.
apiTokenstringYesA Cloudflare API token with permission to send email.
fetchtypeof fetchNoA custom fetch implementation.

Workers binding

Inside a Cloudflare Worker, you can send through a send_email binding instead of the REST API. You don't need an account ID or API token then.

wrangler.jsonc
{
  "send_email": [{ "name": "EMAIL" }],
}
import { createClient } from '@nicogenz/emails-sdk';
import { cloudflare } from '@nicogenz/emails-sdk/cloudflare';

export default {
  async fetch(request, env) {
    const email = createClient({
      provider: cloudflare({ binding: env.EMAIL }),
    });

    await email.send({
      from: 'Acme <[email protected]>',
      to: '[email protected]',
      subject: 'Welcome to Acme',
      html: '<p>Thanks for signing up!</p>',
    });

    return new Response('Sent');
  },
};
OptionTypeRequiredDescription
bindingCloudflareEmailBindingYesThe send_email binding from your Worker's env.

Notes

  • The REST API reports which recipients were delivered, queued, bounced or suppressed. send succeeds as long as Cloudflare accepts the email, and these lists are in raw.
  • Errors thrown by the binding become an EmailError: rate and daily limits map to rate_limited, delivery and internal errors to provider_error, and all other errors to validation. The original error is the cause.
  • tags and idempotencyKey aren't supported. Passing either throws an EmailError with the code unsupported.
  • Cloudflare allows only one replyTo address. Passing more throws an EmailError with the code unsupported.
  • headers must start with X- or be on Cloudflare's header allowlist.
  • An email can have at most 50 recipients across to, cc and bcc, and can be at most 5 MiB including attachments.
  • sendBatch sends the emails one by one, because Cloudflare has no batch endpoint.
Copyright © 2026