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

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.

# `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*
