The problem is how can I catch exception in delivering mail by ActionMailer. For me it sounds impossible, because in this case ActionMailer should sent mail to mailserver, a
This is inspired by the answer given by @sukeerthi-adiga
class ApplicationMailer < ActionMailer::Base
# Add other exceptions you want rescued in the array below
ERRORS_TO_RESCUE = [
Net::SMTPAuthenticationError,
Net::SMTPServerBusy,
Net::SMTPSyntaxError,
Net::SMTPFatalError,
Net::SMTPUnknownError,
Errno::ECONNREFUSED
]
rescue_from *ERRORS_TO_RESCUE do |exception|
# Handle it here
Rails.logger.error("failed to send email")
end
end
The * is the splat operator. It expands an Array into a list of arguments.
More explanation about (*) splat operator