Handle sending mail more properly

With custom sentry reporting issues

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-04-20 15:02:24 +02:00
parent 9a65b29640
commit d98e68203e
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
10 changed files with 46 additions and 18 deletions

View File

@ -592,7 +592,7 @@ defmodule Mobilizon.Federation.ActivityPub do
Enum.each(Users.list_moderators(), fn moderator -> Enum.each(Users.list_moderators(), fn moderator ->
moderator moderator
|> Admin.report(report) |> Admin.report(report)
|> Mailer.deliver_later() |> Mailer.send_email_later()
end) end)
{:ok, activity, report} {:ok, activity, report}

View File

@ -70,7 +70,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
participant, participant,
Map.get(args, :locale, "en") Map.get(args, :locale, "en")
) )
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
end end
{:ok, participant} {:ok, participant}

View File

@ -358,11 +358,11 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
{:ok, %User{} = user} <- Users.update_user_email(user, new_email) do {:ok, %User{} = user} <- Users.update_user_email(user, new_email) do
user user
|> Email.User.send_email_reset_old_email() |> Email.User.send_email_reset_old_email()
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
user user
|> Email.User.send_email_reset_new_email() |> Email.User.send_email_reset_new_email()
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
{:ok, user} {:ok, user}
else else

View File

@ -23,7 +23,7 @@ defmodule Mobilizon.Service.Workers.Notification do
Users.get_user_with_settings!(user_id) do Users.get_user_with_settings!(user_id) do
email email
|> Notification.before_event_notification(participant, locale) |> Notification.before_event_notification(participant, locale)
|> Mailer.deliver_later() |> Mailer.send_email_later()
:ok :ok
end end
@ -48,7 +48,7 @@ defmodule Mobilizon.Service.Workers.Notification do
true <- length(participations) > 0 do true <- length(participations) > 0 do
user user
|> Notification.on_day_notification(participations, total, locale) |> Notification.on_day_notification(participations, total, locale)
|> Mailer.deliver_later() |> Mailer.send_email_later()
:ok :ok
else else
@ -77,7 +77,7 @@ defmodule Mobilizon.Service.Workers.Notification do
true <- length(participations) > 0 do true <- length(participations) > 0 do
user user
|> Notification.weekly_notification(participations, total, locale) |> Notification.weekly_notification(participations, total, locale)
|> Mailer.deliver_later() |> Mailer.send_email_later()
:ok :ok
else else
@ -99,7 +99,7 @@ defmodule Mobilizon.Service.Workers.Notification do
Events.list_participants_for_event(event_id, [:not_approved]) do Events.list_participants_for_event(event_id, [:not_approved]) do
user user
|> Notification.pending_participation_notification(event, total) |> Notification.pending_participation_notification(event, total)
|> Mailer.deliver_later() |> Mailer.send_email_later()
:ok :ok
else else

View File

@ -143,6 +143,6 @@ defmodule Mobilizon.Web.Email.Event do
) do ) do
email email
|> Email.Event.event_updated(actor, old_event, event, diff, timezone, locale) |> Email.Event.event_updated(actor, old_event, event, diff, timezone, locale)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
end end
end end

View File

@ -62,7 +62,7 @@ defmodule Mobilizon.Web.Email.Follow do
|> assign(:follower, follower) |> assign(:follower, follower)
|> assign(:subject, subject) |> assign(:subject, subject)
|> render(:instance_follow) |> render(:instance_follow)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
:ok :ok
end end

View File

@ -42,7 +42,7 @@ defmodule Mobilizon.Web.Email.Group do
|> assign(:group, group) |> assign(:group, group)
|> assign(:subject, subject) |> assign(:subject, subject)
|> render(:group_invite) |> render(:group_invite)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
:ok :ok
end end
@ -70,7 +70,7 @@ defmodule Mobilizon.Web.Email.Group do
|> assign(:group, group) |> assign(:group, group)
|> assign(:subject, subject) |> assign(:subject, subject)
|> render(:group_member_removal) |> render(:group_member_removal)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
:ok :ok
end end
@ -107,7 +107,7 @@ defmodule Mobilizon.Web.Email.Group do
|> assign(:subject, subject) |> assign(:subject, subject)
|> assign(:instance, instance) |> assign(:instance, instance)
|> render(:group_suspension) |> render(:group_suspension)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
:ok :ok
end end
@ -147,7 +147,7 @@ defmodule Mobilizon.Web.Email.Group do
|> assign(:instance, instance) |> assign(:instance, instance)
|> assign(:author, author) |> assign(:author, author)
|> render(:group_deletion) |> render(:group_deletion)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
:ok :ok
else else

View File

@ -3,4 +3,32 @@ defmodule Mobilizon.Web.Email.Mailer do
Mobilizon Mailer. Mobilizon Mailer.
""" """
use Bamboo.Mailer, otp_app: :mobilizon use Bamboo.Mailer, otp_app: :mobilizon
def send_email_later(email) do
try do
Mobilizon.Web.Email.Mailer.deliver_later!(email)
rescue
error ->
Sentry.capture_exception(error,
stacktrace: __STACKTRACE__,
extra: %{extra: "Error while sending email"}
)
reraise error, __STACKTRACE__
end
end
def send_email(email) do
try do
Mobilizon.Web.Email.Mailer.deliver_now!(email)
rescue
error ->
Sentry.capture_exception(error,
stacktrace: __STACKTRACE__,
extra: %{extra: "Error while sending email"}
)
reraise error, __STACKTRACE__
end
end
end end

View File

@ -28,7 +28,7 @@ defmodule Mobilizon.Web.Email.Participation do
email email
|> participation_updated(participation, locale) |> participation_updated(participation, locale)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
end end
:ok :ok
@ -40,7 +40,7 @@ defmodule Mobilizon.Web.Email.Participation do
with %User{locale: locale} = user <- Users.get_user!(user_id) do with %User{locale: locale} = user <- Users.get_user!(user_id) do
user user
|> participation_updated(participation, locale) |> participation_updated(participation, locale)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
:ok :ok
end end

View File

@ -90,7 +90,7 @@ defmodule Mobilizon.Web.Email.User do
def send_confirmation_email(%User{} = user, locale \\ "en") do def send_confirmation_email(%User{} = user, locale \\ "en") do
user user
|> Email.User.confirmation_email(locale) |> Email.User.confirmation_email(locale)
|> Email.Mailer.deliver_later() |> Email.Mailer.send_email_later()
end end
@doc """ @doc """
@ -135,7 +135,7 @@ defmodule Mobilizon.Web.Email.User do
{:ok, %Bamboo.Email{} = mail} <- {:ok, %Bamboo.Email{} = mail} <-
user_updated user_updated
|> Email.User.reset_password_email(locale) |> Email.User.reset_password_email(locale)
|> Email.Mailer.deliver_later() do |> Email.Mailer.send_email_later() do
{:ok, mail} {:ok, mail}
else else
{:error, reason} -> {:error, reason} {:error, reason} -> {:error, reason}