mobilizon/lib/web/email/email.ex

39 lines
1.2 KiB
Elixir
Raw Normal View History

2020-01-26 21:36:50 +01:00
defmodule Mobilizon.Web.Email do
2019-09-17 02:45:32 +02:00
@moduledoc """
The Email context.
"""
use Phoenix.Swoosh, view: Mobilizon.Web.EmailView, layout: {Mobilizon.Web.EmailView, :email}
2019-09-17 02:45:32 +02:00
alias Mobilizon.{Config, Events}
alias Mobilizon.Events.Event
alias Mobilizon.Service.Export.ICalendar
alias Mobilizon.Web.EmailView
@spec base_email(keyword()) :: Swoosh.Email.t()
def base_email(args) do
[reply_to: Config.instance_email_reply_to() || Config.instance_email_from()]
|> Keyword.merge(args)
|> new()
|> from({Config.instance_name(), Config.instance_email_from()})
|> assign(:jsonLDMetadata, nil)
|> assign(:instance_name, Config.instance_name())
|> assign(:offer_unsupscription, true)
|> put_layout({EmailView, :email})
2019-09-17 02:45:32 +02:00
end
def add_event_attachment(%Swoosh.Email{} = email, %Event{id: event_id}) do
with {:ok, %Event{} = event} <- Events.get_event_with_preload(event_id),
{:ok, event_ics_data} <- ICalendar.export_event(event) do
attachment(email, %Swoosh.Attachment{
filename: "#{Slugger.slugify_downcase(event.title)}.ics",
content_type: "text/calendar",
data: event_ics_data
})
else
_ ->
email
end
end
2019-09-17 02:45:32 +02:00
end