Send mail as prop@w5isp.com with reply-to graham@mcintire.me
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:
parent
f7ba94b136
commit
d6e9d80ce9
3 changed files with 18 additions and 22 deletions
|
|
@ -4,14 +4,12 @@ defmodule Microwaveprop.Accounts.UserNotifier do
|
||||||
|
|
||||||
alias Microwaveprop.Mailer
|
alias Microwaveprop.Mailer
|
||||||
|
|
||||||
@default_from {"NTMS Propagation", "noreply@mcintire.me"}
|
|
||||||
|
|
||||||
# Delivers the email using the application mailer.
|
# Delivers the email using the application mailer.
|
||||||
defp deliver(recipient, subject, body) do
|
defp deliver(recipient, subject, body) do
|
||||||
email =
|
email =
|
||||||
new()
|
new()
|
||||||
|> to(recipient)
|
|> to(recipient)
|
||||||
|> from(from_address())
|
|> Mailer.apply_defaults()
|
||||||
|> subject(subject)
|
|> subject(subject)
|
||||||
|> text_body(body)
|
|> text_body(body)
|
||||||
|
|
||||||
|
|
@ -20,14 +18,6 @@ defmodule Microwaveprop.Accounts.UserNotifier do
|
||||||
end
|
end
|
||||||
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 """
|
@doc """
|
||||||
Deliver instructions to confirm a newly registered account.
|
Deliver instructions to confirm a newly registered account.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,20 @@
|
||||||
defmodule Microwaveprop.Mailer do
|
defmodule Microwaveprop.Mailer do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
use Swoosh.Mailer, otp_app: :microwaveprop
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ defmodule Microwaveprop.Radio.EditNotifier do
|
||||||
|
|
||||||
alias Microwaveprop.Mailer
|
alias Microwaveprop.Mailer
|
||||||
|
|
||||||
@default_from {"NTMS Propagation", "noreply@mcintire.me"}
|
|
||||||
|
|
||||||
def deliver_edit_approved(edit) do
|
def deliver_edit_approved(edit) do
|
||||||
edit = Microwaveprop.Repo.preload(edit, [:user, :contact])
|
edit = Microwaveprop.Repo.preload(edit, [:user, :contact])
|
||||||
contact = edit.contact
|
contact = edit.contact
|
||||||
|
|
@ -57,7 +55,7 @@ defmodule Microwaveprop.Radio.EditNotifier do
|
||||||
email =
|
email =
|
||||||
new()
|
new()
|
||||||
|> to(recipient)
|
|> to(recipient)
|
||||||
|> from(from_address())
|
|> Mailer.apply_defaults()
|
||||||
|> subject(subject)
|
|> subject(subject)
|
||||||
|> text_body(body)
|
|> text_body(body)
|
||||||
|
|
||||||
|
|
@ -66,14 +64,6 @@ defmodule Microwaveprop.Radio.EditNotifier do
|
||||||
end
|
end
|
||||||
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
|
defp url do
|
||||||
MicrowavepropWeb.Endpoint.url()
|
MicrowavepropWeb.Endpoint.url()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue