1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-28 19:06:23 +00:00
mobilizon/lib/web/email/email.ex
Thomas Citharel dbdb2bcdab
Use DateTime.utc_now/0 instead of Timex.local/0
Timex.local/0 requires the TZ environment variable to be set

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2020-11-14 19:07:19 +01:00

43 lines
1.2 KiB
Elixir

defmodule Mobilizon.Web.Email do
@moduledoc """
The Email context.
"""
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
alias Ecto.UUID
alias Mobilizon.Config
alias Mobilizon.Web.EmailView
@spec base_email(keyword()) :: Bamboo.Email.t()
def base_email(args) do
instance = Config.instance_config()
args
|> new_email()
|> from({Config.instance_name(), Config.instance_email_from()})
|> put_header("Reply-To", Config.instance_email_reply_to())
|> put_header("Date", date())
|> put_header("Message-Id", message_id())
|> assign(:instance, instance)
|> put_html_layout({EmailView, "email.html"})
|> put_text_layout({EmailView, "email.text"})
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!(DateTime.utc_now(), "{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} {Z}")
end
end
end