Skip to content

PhoenixKit 2.17.0: Template emails no longer need a database row

PhoenixKit 2.17.0 changes how emails sent by template name find their content. A database row is no longer the only source, so Billing’s invoice and receipt emails, and any of your own, can keep working without one.

Three places to find an email’s content

PhoenixKit.Mailer.send_from_template/4 is the function a host app or a module calls to send an email by template name. Billing uses it for its invoice, receipt, credit note and payment confirmation emails. Until now it looked the name up in the email templates table alone and answered {:error, :template_not_found} when there was no row.

It now goes through the same lookup as the sign-in emails, in this order:

  1. an active template in the database,
  2. a host override file for the recipient’s language, under priv/phoenix_kit_templates,
  3. content the caller passes in the new :defaults option.

On a site that has the template in the database, that row still wins, so nothing changes in what is sent.

New options

  • :defaults takes a map of %{subject:, text:, html:}, or a function without arguments that returns one. Use the function for text built with gettext/1: it runs in the recipient’s language.
  • :locale renders the email in a given language.
  • :paths sets the folders searched for override files, in place of the configured ones.

Without :locale, the language comes from the recipient. A plain email address carries no preference, so such an email is rendered in the site’s content language, where the old code used English unless a locale was passed.

Usage counting on the template only happens when a database template supplied the content. The send is logged either way.

Upgrading

No migration and no configuration. Update the dependency. If your app calls send_from_template/4, add :defaults to those calls, so the emails keep a source of content if the templates table goes away. Until then, adding them changes nothing. The {:error, :template_inactive} result is gone from the documentation; it could never be returned.

Full release notes: PhoenixKit 2.17.0

2.17.0 · 6 September 2026

Changed

  • Mailer.send_from_template/4 no longer depends on the email templates table. It is core’s generic host-facing send API, and it resolved names from the database alone — answering {:error, :template_not_found} when there was no row. That table is being retired, and phoenix_kit_billing reaches through this function for its invoice, receipt, credit-note and payment-confirmation emails, so dropping the table with this path untouched would have stopped those emails silently, with an error shape the caller already tolerates.

    It now resolves through PhoenixKit.Email.Content, in order: an active database template, then a host override file for the recipient’s locale, then the caller’s own :defaults.

    Nothing changes for an install that has a row — the database layer still wins, exactly as it does for the auth emails. This ships ahead of the schema move on purpose, so no caller is ever in a window where its emails depend on a path that no longer works.

    Three new options:

    Option Effect
    :defaults content to fall back to — a %{subject:, text:, html:} map, or a zero-arity function returning one. Prefer the function for gettext/1 content: it is evaluated inside the recipient’s locale
    :locale render in this locale instead of the one resolved from the recipient (a bare address carries no preference, so that falls through to the site’s content language)
    :paths host override roots to search, overriding the configured ones

    A host or module that calls this function should add :defaults before the table is retired. Until then, adding them changes nothing.

  • PhoenixKit.Email.Content.resolve/5 accepts :locale, for callers whose recipient is a bare address rather than a user, and treats an explicit nil :paths as “use the configured roots”.

Fixed

  • {:error, :template_inactive} is documented as no longer returned by send_from_template/4, and never was: get_active_template_by_name/1 already filters on status == "active", so the branch that returned it was unreachable.

PhoenixKit 2.17.0. Install or update: {:phoenix_kit, "~> 2.17"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.