1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-24 17:01:45 +00:00
mobilizon/lib/web/email/email.ex

40 lines
1.3 KiB
Elixir
Raw Normal View History

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.
"""
use Phoenix.Swoosh, view: Mobilizon.Web.EmailView, layout: {Mobilizon.Web.EmailView, :email}
2019-09-17 00:45:32 +00: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 00:45:32 +00:00
end
@spec add_event_attachment(Swoosh.Email.t(), Event.t()) :: Swoosh.Email.t()
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 00:45:32 +00:00
end