2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.Email do
|
2019-09-17 00:45:32 +00:00
|
|
|
@moduledoc """
|
|
|
|
The Email context.
|
|
|
|
"""
|
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
2019-09-17 00:45:32 +00:00
|
|
|
|
2020-11-13 13:02:33 +00:00
|
|
|
alias Ecto.UUID
|
2019-09-17 00:45:32 +00:00
|
|
|
alias Mobilizon.Config
|
2020-01-28 18:18:33 +00:00
|
|
|
alias Mobilizon.Web.EmailView
|
|
|
|
|
2019-09-23 17:33:58 +00:00
|
|
|
@spec base_email(keyword()) :: Bamboo.Email.t()
|
|
|
|
def base_email(args) do
|
|
|
|
instance = Config.instance_config()
|
|
|
|
|
2019-09-30 16:18:04 +00:00
|
|
|
args
|
|
|
|
|> new_email()
|
2019-11-19 10:12:59 +00:00
|
|
|
|> from({Config.instance_name(), Config.instance_email_from()})
|
2019-09-23 17:33:58 +00:00
|
|
|
|> put_header("Reply-To", Config.instance_email_reply_to())
|
2020-11-13 13:02:33 +00:00
|
|
|
|> put_header("Date", date())
|
|
|
|
|> put_header("Message-Id", message_id())
|
2019-09-23 17:33:58 +00:00
|
|
|
|> assign(:instance, instance)
|
2020-01-28 18:18:33 +00:00
|
|
|
|> put_html_layout({EmailView, "email.html"})
|
|
|
|
|> put_text_layout({EmailView, "email.text"})
|
2019-09-17 00:45:32 +00:00
|
|
|
end
|
2020-11-13 13:02:33 +00:00
|
|
|
|
|
|
|
# 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
|
2020-11-14 18:07:19 +00:00
|
|
|
Timex.format!(DateTime.utc_now(), "{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} {Z}")
|
2020-11-13 13:02:33 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-17 00:45:32 +00:00
|
|
|
end
|