# `Accrue.Mailer`
[🔗](https://github.com/szTheory/accrue/blob/accrue-v1.0.0/lib/accrue/mailer.ex#L1)

Behaviour + facade for the Accrue transactional email pipeline.

## Semantic API

Callers invoke `Accrue.Mailer.deliver/2` with an email **type atom** and a
plain **assigns map**. The configured adapter (`Accrue.Mailer.Default` by
default) is responsible for turning the type + assigns into a rendered email
and delivering it. Callers never construct a `%Swoosh.Email{}` directly —
that is the adapter's job, keeping call sites decoupled from the email
rendering pipeline.

## Per-type kill switch

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

## Telemetry

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.

# `assigns`

```elixir
@type assigns() :: map()
```

# `email_type`

```elixir
@type email_type() :: atom()
```

# `deliver`

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

# `deliver`

```elixir
@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?`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
