Fix email missing headers
Close #426 #491 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
b5c66ae12d
commit
782c01e85d
|
@ -5,8 +5,8 @@ defmodule Mobilizon.Web.Email do
|
||||||
|
|
||||||
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
||||||
|
|
||||||
|
alias Ecto.UUID
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
alias Mobilizon.Web.EmailView
|
alias Mobilizon.Web.EmailView
|
||||||
|
|
||||||
@spec base_email(keyword()) :: Bamboo.Email.t()
|
@spec base_email(keyword()) :: Bamboo.Email.t()
|
||||||
|
@ -17,8 +17,27 @@ defmodule Mobilizon.Web.Email do
|
||||||
|> new_email()
|
|> new_email()
|
||||||
|> from({Config.instance_name(), Config.instance_email_from()})
|
|> from({Config.instance_name(), Config.instance_email_from()})
|
||||||
|> put_header("Reply-To", Config.instance_email_reply_to())
|
|> put_header("Reply-To", Config.instance_email_reply_to())
|
||||||
|
|> put_header("Date", date())
|
||||||
|
|> put_header("Message-Id", message_id())
|
||||||
|> assign(:instance, instance)
|
|> assign(:instance, instance)
|
||||||
|> put_html_layout({EmailView, "email.html"})
|
|> put_html_layout({EmailView, "email.html"})
|
||||||
|> put_text_layout({EmailView, "email.text"})
|
|> put_text_layout({EmailView, "email.text"})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generating an UUID randomly causes Bamboo.Test.assert_delivered_email/1 to fail
|
||||||
|
defp message_id do
|
||||||
|
if Application.fetch_env!(:mobilizon, :env) == :test do
|
||||||
|
"TEST_ENV_MESSAGE_ID@#{Config.instance_hostname()}"
|
||||||
|
else
|
||||||
|
"#{UUID.generate()}@#{Config.instance_hostname()}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp date do
|
||||||
|
if Application.fetch_env!(:mobilizon, :env) == :test do
|
||||||
|
"REMOVED FOR TESTING"
|
||||||
|
else
|
||||||
|
Timex.format!(Timex.local(), "{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} {Z}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue