如何判断Rails动作邮件传递是否失败?

Der*_*rek 6 ruby ruby-on-rails actionmailer

在我的项目中,我使用的是Rails 4.1.1和Ruby 2.1.1.我正在阅读mail宝石,但不知道如何检查是否deliver失败(由于任何原因).

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
Run Code Online (Sandbox Code Playgroud)

Dan*_*nny 10

http://guides.rubyonrails.org/action_mailer_basics.html中所述,您可以设置

config.action_mailer.raise_delivery_errors = true
Run Code Online (Sandbox Code Playgroud)

这样,如果无法进行交付,Rails将引发错误

  • 引发的错误是什么?所以我可以`rescue_from`它 (2认同)
  • 所有例外情况都是https://robots.thoughtbot.com/i-accidentally-the-whole-smtp-exception.根据错误是:(IOError,Net :: SMTPAuthenticationError Net :: SMTPServerBusy,Net :: SMTPUnknownError,TimeoutError) (2认同)