From d6e9d80ce9d2938b168b35997e7282a1d339c52d Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 12 Apr 2026 14:00:38 -0500 Subject: [PATCH] Send mail as prop@w5isp.com with reply-to graham@mcintire.me MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Centralized the From and Reply-To headers in Microwaveprop.Mailer.apply_defaults/1 so UserNotifier and EditNotifier can't drift. Drops the EMAIL_FROM env var override — both values are hardcoded now. --- lib/microwaveprop/accounts/user_notifier.ex | 12 +----------- lib/microwaveprop/mailer.ex | 16 ++++++++++++++++ lib/microwaveprop/radio/edit_notifier.ex | 12 +----------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/microwaveprop/accounts/user_notifier.ex b/lib/microwaveprop/accounts/user_notifier.ex index 06ae9476..d819bd68 100644 --- a/lib/microwaveprop/accounts/user_notifier.ex +++ b/lib/microwaveprop/accounts/user_notifier.ex @@ -4,14 +4,12 @@ defmodule Microwaveprop.Accounts.UserNotifier do alias Microwaveprop.Mailer - @default_from {"NTMS Propagation", "noreply@mcintire.me"} - # Delivers the email using the application mailer. defp deliver(recipient, subject, body) do email = new() |> to(recipient) - |> from(from_address()) + |> Mailer.apply_defaults() |> subject(subject) |> text_body(body) @@ -20,14 +18,6 @@ defmodule Microwaveprop.Accounts.UserNotifier do end end - defp from_address do - case System.get_env("EMAIL_FROM") do - nil -> @default_from - "" -> @default_from - addr -> {"NTMS Propagation", addr} - end - end - @doc """ Deliver instructions to confirm a newly registered account. """ diff --git a/lib/microwaveprop/mailer.ex b/lib/microwaveprop/mailer.ex index 91793765..40b743fe 100644 --- a/lib/microwaveprop/mailer.ex +++ b/lib/microwaveprop/mailer.ex @@ -1,4 +1,20 @@ defmodule Microwaveprop.Mailer do @moduledoc false use Swoosh.Mailer, otp_app: :microwaveprop + + import Swoosh.Email + + @from {"NTMS Propagation", "prop@w5isp.com"} + @reply_to "graham@mcintire.me" + + @doc """ + Apply the site-wide `From:` and `Reply-To:` headers to an outgoing email. + Centralized here so `UserNotifier` and `EditNotifier` can't drift. + """ + @spec apply_defaults(Swoosh.Email.t()) :: Swoosh.Email.t() + def apply_defaults(email) do + email + |> from(@from) + |> reply_to(@reply_to) + end end diff --git a/lib/microwaveprop/radio/edit_notifier.ex b/lib/microwaveprop/radio/edit_notifier.ex index 14648718..2ccfc70c 100644 --- a/lib/microwaveprop/radio/edit_notifier.ex +++ b/lib/microwaveprop/radio/edit_notifier.ex @@ -4,8 +4,6 @@ defmodule Microwaveprop.Radio.EditNotifier do alias Microwaveprop.Mailer - @default_from {"NTMS Propagation", "noreply@mcintire.me"} - def deliver_edit_approved(edit) do edit = Microwaveprop.Repo.preload(edit, [:user, :contact]) contact = edit.contact @@ -57,7 +55,7 @@ defmodule Microwaveprop.Radio.EditNotifier do email = new() |> to(recipient) - |> from(from_address()) + |> Mailer.apply_defaults() |> subject(subject) |> text_body(body) @@ -66,14 +64,6 @@ defmodule Microwaveprop.Radio.EditNotifier do end end - defp from_address do - case System.get_env("EMAIL_FROM") do - nil -> @default_from - "" -> @default_from - addr -> {"NTMS Propagation", addr} - end - end - defp url do MicrowavepropWeb.Endpoint.url() end