Answer the question
In order to leave comments, you need to log in
How to catch an email sending error?
Gemfile:
gem 'resque_mailer', '2.2.7' # Send mail asynchronously
controller:
def some
MyMailer.send(parameter).deliver
rescue Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e
#Здесь я могу отловить ошибку, но здесь мне не надо
end
class MyMailer < ActionMailer::Base
include Resque::Mailer
def send param
smtp_sets = LoadSmtpSets(1)
mail subject: 'some', from: '[email protected]', delivery_method_options: smtp_sets
rescue Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e
smtp_sets = LoadSmtpSets(2)
mail subject: 'some', from: '[email protected]', delivery_method_options: smtp_sets
#этот блок никогда не вызывается, а надо отловить ошибку, которую дает яндекс, к примеру
end
end
Answer the question
In order to leave comments, you need to log in
Custom handling of errors that arise when sending a message is possible by assigning a lambda to the error_handler attribute. There are two supported lambdas for backwards compatiability.
The first lamba will be deprecated in a future release:
Resque::Mailer.error_handler = lambda { |mailer, message, error|
# some custom error handling code here in which you optionally re-raise the error
}
The new lamba contains two other arguments, action and args, which allows mailers to be requeued on failure:
Resque::Mailer.error_handler = lambda { |mailer, message, error, action, args|
# Necessary to re-enqueue jobs that receive the SIGTERM signal
if error.is_a?(Resque::TermException)
Resque enqueue(mailer, action, *args)
else
raise error
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question