Emails

The behaviour every email implements: a name and description for the admin panel, a subject, an optional preheader (the preview text inboxes show after the subject), an HTML body, and a plain-text body, which spam filters expect alongside HTML.

v1.8.3
Level: Hard
14
602
66

Sending

deliver/3 renders a template for a user and sends it, returning {:ok, email} like the generated notifier did. build/3 stops short of sending, so other features can add headers first: campaign emails add unsubscribe headers this way. render/2 and render_sample/2 produce the subject, preheader, HTML, and text for previews, and deliver_test/2 sends a template with its samples and "[Test]" in the subject.

The sender comes from EMAIL_FROM_NAME and EMAIL_FROM_ADDRESS .

Templates

The behaviour every email implements: a name and description for the admin panel, a subject, an optional preheader (the preview text inboxes show after the subject), an HTML body, and a plain-text body, which spam filters expect alongside HTML.

Every template gets :user plus whatever its sender passes, like a login URL. sample_assigns/0 supplies stand-ins for those, so the admin panel can preview any template without real data. use MyApp.Emails.Template brings in Phoenix components and the shared layout, so a template's body is ordinary HEEx.

The shared chrome: a centered card on a light background, a hidden preheader, and an optional footer. Styles are inline, since many email clients ignore <style> tags, and the structure uses tables, which render consistently in Outlook. The footer's unsubscribe link only appears when unsubscribe_url is passed, which transactional email never does. heading/1 , paragraph/1 , button/1 , and fine_print/1 keep templates short.

The catalog names each template, for the admin panel's routes. Code sends templates by module.

Admin

Every template in code, with what it's for.

A template rendered with its sample data, and a form to send it as a test to any address. An unknown key goes back to the list.

The preview shows the subject and preheader, the HTML in a sandboxed iframe so the email's styles stay isolated, and the text version on a second tab. It and the test-send form are components, so Email Campaigns reuses them for marketing templates.

An "Emails" section in the admin sidebar.

The template pages are in :admin_authenticated .

Tests

Renders every template from its samples, so a broken template fails CI. Also covers delivery, the account emails, and test sends.