Handle sending mail more properly
With custom sentry reporting issues Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
9a65b29640
commit
d98e68203e
|
@ -592,7 +592,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
|||
Enum.each(Users.list_moderators(), fn moderator ->
|
||||
moderator
|
||||
|> Admin.report(report)
|
||||
|> Mailer.deliver_later()
|
||||
|> Mailer.send_email_later()
|
||||
end)
|
||||
|
||||
{:ok, activity, report}
|
||||
|
|
|
@ -70,7 +70,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
|||
participant,
|
||||
Map.get(args, :locale, "en")
|
||||
)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
end
|
||||
|
||||
{:ok, participant}
|
||||
|
|
|
@ -358,11 +358,11 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
|||
{:ok, %User{} = user} <- Users.update_user_email(user, new_email) do
|
||||
user
|
||||
|> Email.User.send_email_reset_old_email()
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
user
|
||||
|> Email.User.send_email_reset_new_email()
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
{:ok, user}
|
||||
else
|
||||
|
|
|
@ -23,7 +23,7 @@ defmodule Mobilizon.Service.Workers.Notification do
|
|||
Users.get_user_with_settings!(user_id) do
|
||||
email
|
||||
|> Notification.before_event_notification(participant, locale)
|
||||
|> Mailer.deliver_later()
|
||||
|> Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
@ -48,7 +48,7 @@ defmodule Mobilizon.Service.Workers.Notification do
|
|||
true <- length(participations) > 0 do
|
||||
user
|
||||
|> Notification.on_day_notification(participations, total, locale)
|
||||
|> Mailer.deliver_later()
|
||||
|> Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
else
|
||||
|
@ -77,7 +77,7 @@ defmodule Mobilizon.Service.Workers.Notification do
|
|||
true <- length(participations) > 0 do
|
||||
user
|
||||
|> Notification.weekly_notification(participations, total, locale)
|
||||
|> Mailer.deliver_later()
|
||||
|> Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
else
|
||||
|
@ -99,7 +99,7 @@ defmodule Mobilizon.Service.Workers.Notification do
|
|||
Events.list_participants_for_event(event_id, [:not_approved]) do
|
||||
user
|
||||
|> Notification.pending_participation_notification(event, total)
|
||||
|> Mailer.deliver_later()
|
||||
|> Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
else
|
||||
|
|
|
@ -143,6 +143,6 @@ defmodule Mobilizon.Web.Email.Event do
|
|||
) do
|
||||
email
|
||||
|> Email.Event.event_updated(actor, old_event, event, diff, timezone, locale)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -62,7 +62,7 @@ defmodule Mobilizon.Web.Email.Follow do
|
|||
|> assign(:follower, follower)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:instance_follow)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ defmodule Mobilizon.Web.Email.Group do
|
|||
|> assign(:group, group)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:group_invite)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ defmodule Mobilizon.Web.Email.Group do
|
|||
|> assign(:group, group)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:group_member_removal)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
@ -107,7 +107,7 @@ defmodule Mobilizon.Web.Email.Group do
|
|||
|> assign(:subject, subject)
|
||||
|> assign(:instance, instance)
|
||||
|> render(:group_suspension)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
@ -147,7 +147,7 @@ defmodule Mobilizon.Web.Email.Group do
|
|||
|> assign(:instance, instance)
|
||||
|> assign(:author, author)
|
||||
|> render(:group_deletion)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
else
|
||||
|
|
|
@ -3,4 +3,32 @@ defmodule Mobilizon.Web.Email.Mailer do
|
|||
Mobilizon Mailer.
|
||||
"""
|
||||
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
|
||||
|
|
|
@ -28,7 +28,7 @@ defmodule Mobilizon.Web.Email.Participation do
|
|||
|
||||
email
|
||||
|> participation_updated(participation, locale)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
end
|
||||
|
||||
:ok
|
||||
|
@ -40,7 +40,7 @@ defmodule Mobilizon.Web.Email.Participation do
|
|||
with %User{locale: locale} = user <- Users.get_user!(user_id) do
|
||||
user
|
||||
|> participation_updated(participation, locale)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
|
|
@ -90,7 +90,7 @@ defmodule Mobilizon.Web.Email.User do
|
|||
def send_confirmation_email(%User{} = user, locale \\ "en") do
|
||||
user
|
||||
|> Email.User.confirmation_email(locale)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|> Email.Mailer.send_email_later()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -135,7 +135,7 @@ defmodule Mobilizon.Web.Email.User do
|
|||
{:ok, %Bamboo.Email{} = mail} <-
|
||||
user_updated
|
||||
|> Email.User.reset_password_email(locale)
|
||||
|> Email.Mailer.deliver_later() do
|
||||
|> Email.Mailer.send_email_later() do
|
||||
{:ok, mail}
|
||||
else
|
||||
{:error, reason} -> {:error, reason}
|
||||
|
|
Loading…
Reference in a new issue