SwooshCloudflare
Swoosh adapter for Cloudflare Email Service.
Installation
def deps do
[
{:swoosh_cloudflare, "~> 0.1"}
]
endConfiguration
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
endUsage
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
fromaddress 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:
| Reason | HTTP | Cloudflare code |
|---|---|---|
:invalid_request | 400 | 10001 |
:invalid_content | 400 | 10200 |
:message_too_large | 400 | 10202 |
:sending_disabled | 403 | 10203 |
:rate_limited | 429 | 10004 |
:server_error | 500 | 10002 |
:unknown_error | any | — |
License
MIT