在开发中尝试exception_notification时ActionMailer :: Base :: NullMail

svo*_*oop 4 ruby-on-rails ruby-on-rails-3 exception-notification exception-notifier

我想将exception_notification gem添加到我们的应用程序中,但是,当我尝试手动触发邮件时会发生这种情况:

exception
# => #<ZeroDivisionError: divided by 0>
ExceptionNotifier::Notifier.exception_notification(request.env, exception)
# => #<ActionMailer::Base::NullMail:0x007fa81bc7c610>
ExceptionNotifier::Notifier.background_exception_notification(exception)
# => #<ActionMailer::Base::NullMail:0x007fa81bf58190>
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,在某个控制器中rescue_from Exception故意调用之后,控制台位于ApplicationController 内部的断点处1/0.

我也在使用delayed_job,但是 - 毫不奇怪 - ExceptionNotifier::Notifier.background_exception_notification(exception).deliver不会假装什么.

我已经设置config.consider_all_requests_local = false了开发,但仍然exception_notification实例化NullMail.在应用程序的其他部分,邮件工作正常并使用sendmail.

我在这里做错了什么想法?谢谢你的帮助!

spy*_*yle 9

您可能正在使用旧版本的ExceptionNotifier和更新版本的ActiveMailer :: Base.不在电子邮件功能中调用mail命令将导致返回ActionMailer :: Base :: NullMail实例而不是Mail实例.

来自文档:

class Notifier < ActionMailer::Base
  default :from => 'no-reply@example.com',
         :return_path => 'system@example.com'

  def welcome(recipient)
    @account = recipient
    mail(:to => recipient.email_address_with_name,
         :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
  end
end
Run Code Online (Sandbox Code Playgroud)