Accrue.Mailer behaviour (accrue v0.3.0)

Copy Markdown View Source

Behaviour + facade for the Accrue transactional email pipeline (MAIL-01, D-21).

Semantic API

Callers invoke Accrue.Mailer.deliver/2 with an email type atom and a plain assigns map — never a %Swoosh.Email{} struct. The configured adapter (Accrue.Mailer.Default by default) is responsible for turning the type + assigns into an actual email and delivering it. This is D-21: callers never construct %Swoosh.Email{} — that's the pipeline's job.

Kill switch (D-25)

Set config :accrue, :emails, [<type>: false] to disable a specific transactional email. deliver/2 returns {:ok, :skipped} without enqueueing. The :emails schema key is defined by Accrue.Config.

Telemetry (D-28, T-MAIL-02)

Every deliver/2 call emits [:accrue, :mailer, :deliver, :start | :stop | :exception] with %{email_type: atom, customer_id: binary | nil} metadata. Raw assigns and rendered email bodies are NEVER placed in metadata — they may carry PII.

Summary

Functions

Delivers a transactional email by type + assigns. Delegates to the configured adapter (default Accrue.Mailer.Default).

Returns true if the given email type is not disabled via the :emails kill switch.

Types

assigns()

@type assigns() :: map()

email_type()

@type email_type() :: atom()

Callbacks

deliver(email_type, assigns)

@callback deliver(email_type(), assigns()) :: {:ok, term()} | {:error, term()}

Functions

deliver(type, assigns)

@spec deliver(email_type(), assigns()) :: {:ok, term()} | {:error, term()}

Delivers a transactional email by type + assigns. Delegates to the configured adapter (default Accrue.Mailer.Default).

Returns {:ok, :skipped} when the email type is disabled via the :emails kill switch. Otherwise returns whatever the adapter returns (typically {:ok, %Oban.Job{}} for async enqueue).

enabled?(type)

@spec enabled?(email_type()) :: boolean()

Returns true if the given email type is not disabled via the :emails kill switch.