Helpers for the Cloudflare Email Service beyond Swoosh.Adapters.Cloudflare.
send_raw/4sends a pre-built MIME message.put_list_unsubscribe/3sets the one-click unsubscribe headers.SwooshCloudflare.Suppressionsmanages the suppression list.
All functions take the same config keyword list as the mailer
(:api_token, :account_id, and optionally :base_url):
config = Application.get_env(:my_app, MyApp.Mailer)
Summary
Functions
Sets the List-Unsubscribe header, and by default List-Unsubscribe-Post
for RFC 8058 one-click unsubscribe.
Sends a full RFC 5322 MIME message through the send_raw endpoint.
Functions
@spec put_list_unsubscribe(Swoosh.Email.t(), String.t(), keyword()) :: Swoosh.Email.t()
Sets the List-Unsubscribe header, and by default List-Unsubscribe-Post
for RFC 8058 one-click unsubscribe.
url must be an https:// URL, otherwise ArgumentError is raised.
Options:
:mailto- an address added as a<mailto:...>entry:one_click- whenfalse,List-Unsubscribe-Postis not set (defaulttrue)
Example
email
|> SwooshCloudflare.put_list_unsubscribe("https://example.com/unsubscribe/abc",
mailto: "unsubscribe@example.com"
)sets List-Unsubscribe to
<https://example.com/unsubscribe/abc>, <mailto:unsubscribe@example.com> and
List-Unsubscribe-Post to List-Unsubscribe=One-Click.
@spec send_raw(String.t(), String.t(), [String.t()], keyword()) :: {:ok, Swoosh.Adapters.Cloudflare.send_result()} | {:error, Swoosh.Adapters.Cloudflare.error()}
Sends a full RFC 5322 MIME message through the send_raw endpoint.
from is the envelope sender and recipients the envelope recipients.
Returns the same values as the mailer when using Swoosh.Adapters.Cloudflare:
{:ok, %{id: ..., delivered: [...], permanent_bounces: [...], queued: [...], suppressed_recipients: [...]}},
{:error, {status, reason, body}} or {:error, {429, :rate_limited, retry_after}}.
Raises ArgumentError if :api_token or :account_id is missing from config.
Example
SwooshCloudflare.send_raw(mime, "noreply@example.com", ["alice@example.com"], config)