SwooshCloudflare (SwooshCloudflare v0.7.1)

Copy Markdown View Source

Helpers for the Cloudflare Email Service beyond Swoosh.Adapters.Cloudflare.

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

put_list_unsubscribe(email, url, opts \\ [])

@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 - when false, List-Unsubscribe-Post is not set (default true)

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.

send_raw(mime_message, from, recipients, config)

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)