7

In my project, I'm using Rails 4.1.1 and Ruby 2.1.1. I was reading the mail gem, but wasn't sure how to check if the deliver failed (for any reason).

result = UserMailer.signup.deliver
if result.action == 'failed' or result.bounced?
    # How can you tell if a deliver has failed?
    # Do stuff here if failed
end
ekremkaraca
  • 1,453
  • 2
  • 18
  • 37
Derek
  • 11,980
  • 26
  • 103
  • 162

1 Answers1

13

As described in http://guides.rubyonrails.org/action_mailer_basics.html, you can set

config.action_mailer.raise_delivery_errors = true

this way, Rails will raise an error in case the delivery can't take place

Danny
  • 5,945
  • 4
  • 32
  • 52
  • 2
    What is the error that is raised? So I can `rescue_from` it – Derek Jun 01 '14 at 17:38
  • Derek - I've been looking myself for a list, but can't find it. I would simply catch them all, putting your rescue just around the deliver call – Danny Jun 01 '14 at 18:00
  • 3
    All the exceptions https://robots.thoughtbot.com/i-accidentally-the-whole-smtp-exception . According to that errors are: (IOError, Net::SMTPAuthenticationError Net::SMTPServerBusy, Net::SMTPUnknownError, TimeoutError) – Felix Oct 06 '15 at 13:52