demarches-normaliennes/app/mailers/concerns/mailer_monitoring_concern.rb
2024-08-22 09:26:48 +02:00

24 lines
662 B
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
module MailerMonitoringConcern
extend ActiveSupport::Concern
included do
# Dont retry to send a message if the server rejects the recipient address
rescue_from Net::SMTPSyntaxError do |_exception|
message.perform_deliveries = false
end
rescue_from Net::SMTPServerBusy do |exception|
if /unexpected recipients/.match?(exception.message)
message.perform_deliveries = false
end
end
rescue_from Dolist::IgnorableError, with: :log_delivery_error
def log_delivery_error(exception)
EmailEvent.create_from_message!(message, status: "dispatch_error")
end
end
end