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.
This commit is contained in:
Graham McIntire 2026-04-12 14:00:38 -05:00
parent f7ba94b136
commit d6e9d80ce9
3 changed files with 18 additions and 22 deletions

View file

@ -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.
"""

View file

@ -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

View file

@ -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