Swoosh adapter for Cloudflare Email Service.

Installation

def deps do
  [
    {:swoosh_cloudflare, "~> 0.1"}
  ]
end

Configuration

config :my_app, MyApp.Mailer,
  adapter: Swoosh.Adapters.Cloudflare,
  api_token: System.get_env("CLOUDFLARE_EMAIL_TOKEN"),
  account_id: System.get_env("CLOUDFLARE_ACCOUNT_ID")

Define your mailer module:

defmodule MyApp.Mailer do
  use Swoosh.Mailer, otp_app: :my_app
end

Usage

import Swoosh.Email

new()
|> to({"Alice", "alice@example.com"})
|> from({"My App", "noreply@yourdomain.com"})
|> subject("Welcome!")
|> html_body("<h1>Hello, Alice!</h1>")
|> MyApp.Mailer.deliver()

Limitations

  • Verified addresses only: New accounts can only send to addresses verified in your Cloudflare dashboard. Paid plans unlock general sending.
  • Domain requirement: The from address must belong to a domain with Email Routing active in your Cloudflare account.
  • 50 recipients max per email.
  • 5 MiB max total message size.

Error handling

deliver/1 returns {:error, {http_status, reason}} on API errors:

ReasonHTTPCloudflare code
:invalid_request40010001
:invalid_content40010200
:message_too_large40010202
:sending_disabled40310203
:rate_limited42910004
:server_error50010002
:unknown_errorany

License

MIT