refactor(email): share build/deliver skeleton across join emails
This commit is contained in:
parent
98ff6c1944
commit
8ae8d92df0
4 changed files with 61 additions and 65 deletions
|
|
@ -2,15 +2,10 @@ defmodule MvWeb.Emails.JoinConfirmationEmail do
|
|||
@moduledoc """
|
||||
Sends the join request confirmation email (double opt-in) using the unified email layout.
|
||||
"""
|
||||
use Phoenix.Swoosh,
|
||||
view: MvWeb.EmailsView,
|
||||
layout: {MvWeb.EmailLayoutView, "layout.html"}
|
||||
|
||||
use MvWeb, :verified_routes
|
||||
import Swoosh.Email
|
||||
use Gettext, backend: MvWeb.Gettext, otp_app: :mv
|
||||
|
||||
alias Mv.Mailer
|
||||
alias MvWeb.Emails.JoinEmail
|
||||
|
||||
@doc """
|
||||
Sends the join confirmation email to the given address with the confirmation link.
|
||||
|
|
@ -31,22 +26,9 @@ defmodule MvWeb.Emails.JoinConfirmationEmail do
|
|||
confirm_url = url(~p"/confirm_join/#{token}")
|
||||
subject = gettext("Confirm your membership request")
|
||||
|
||||
assigns = %{
|
||||
JoinEmail.deliver(email_address, "join_confirmation.html", subject, %{
|
||||
confirm_url: confirm_url,
|
||||
subject: subject,
|
||||
app_name: Mailer.mail_from() |> elem(0),
|
||||
locale: Gettext.get_locale(MvWeb.Gettext),
|
||||
resend: Keyword.get(opts, :resend, false)
|
||||
}
|
||||
|
||||
email =
|
||||
new()
|
||||
|> from(Mailer.mail_from())
|
||||
|> to(email_address)
|
||||
|> subject(subject)
|
||||
|> put_view(MvWeb.EmailsView)
|
||||
|> render_body("join_confirmation.html", assigns)
|
||||
|
||||
Mailer.deliver(email, Mailer.smtp_config())
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue