From 4580dc4bd85b8b7b552def15677990a7d5577561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Vidal?= Date: Tue, 4 Jun 2024 00:05:19 -0300 Subject: [PATCH] Always use SMTP_FROM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrés Vidal --- backend/lib/richard_burton/mailer_smtp.ex | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/lib/richard_burton/mailer_smtp.ex b/backend/lib/richard_burton/mailer_smtp.ex index 094425d6..7ba42008 100644 --- a/backend/lib/richard_burton/mailer_smtp.ex +++ b/backend/lib/richard_burton/mailer_smtp.ex @@ -36,25 +36,31 @@ defmodule RichardBurton.Mailer.SMTP do end @spec get_swoosh_email(RichardBurton.Email.t()) :: Swoosh.Email.t() - defp get_swoosh_email(email = %{address: address, subject: subject, message: message, to: nil}) do + defp get_swoosh_email(email = %{message: message, to: nil}) do new( - from: {get_contact_name(email), address}, + from: get_from(), to: System.get_env("SMTP_FROM"), - subject: subject, + subject: get_subject(email), text_body: message ) end @spec get_swoosh_email(RichardBurton.Email.t()) :: Swoosh.Email.t() - defp get_swoosh_email(email = %{address: address, subject: subject, message: message, to: to}) do + defp get_swoosh_email(%{subject: subject, message: message, to: to}) do new( - from: {get_contact_name(email), address}, + from: get_from(), to: to, subject: subject, text_body: message ) end + defp get_from(), + do: {System.get_env("SMTP_NAME"), System.get_env("SMTP_FROM")} + + defp get_subject(email = %{address: address, subject: subject}), + do: "#{subject} (from #{get_contact_name(email)}<#{address}>)" + defp get_contact_name(%{name: name, institution: nil}), do: name defp get_contact_name(%{name: name, institution: ""}), do: name defp get_contact_name(%{name: name, institution: institution}), do: "#{name} (#{institution})"