Ruby on rails 在开发中尝试异常通知时,ActionMailer::Base::NullMail
我想将异常通知gem添加到我们的应用程序中,但是,当我尝试手动触发邮件时会发生这种情况:Ruby on rails 在开发中尝试异常通知时,ActionMailer::Base::NullMail,ruby-on-rails,ruby-on-rails-3,exception-notification,exception-notifier,Ruby On Rails,Ruby On Rails 3,Exception Notification,Exception Notifier,我想将异常通知gem添加到我们的应用程序中,但是,当我尝试手动触发邮件时会发生这种情况: exception # => #<ZeroDivisionError: divided by 0> ExceptionNotifier::Notifier.exception_notification(request.env, exception) # => #<ActionMailer::Base::NullMail:0x007fa81bc7c610> Exceptio
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>
异常
# => #
ExceptionNotifier::Notifier.exception\u通知(request.env,exception)
# => #
异常通知程序::通知程序。后台异常通知(异常)
# => #
在上面的示例中,在某个控制器中经过深思熟虑的1/0
之后,控制台位于ApplicationController中的rescue\u from Exception
内的断点处
我也在使用延迟的任务,但是-毫不奇怪-异常通知程序::通知程序。后台异常通知(异常)。传递
不会假脱机任何内容
我已经在开发中设置了config.consumer\u all\u requests\u local=false
,但异常通知仍然实例化了NullMail。在应用程序的其他部分,邮件发送程序工作正常,可以使用sendmail
知道我做错了什么吗?谢谢你的帮助 您可能正在使用旧版本的ExceptionNotifier和更新版本的ActiveMailer::Base。不在电子邮件功能中调用mail命令将导致返回ActionMailer::Base::NullMail实例,而不是邮件实例 发件人: 类通知程序
我让测试/rspec返回NullMail对象。解决方案很简单,我的代码是:
def my_mail(foo)
mail(
to: to,
from: from,
subject: @sample_item.campaign_market.campaign.translation_for(language_id, 'sample_item_mailer.request_review.subject'),
content_type: "text/html"
)
@sample_item.update_attributes!({feedback_requested: true, review_requested_at: Time.now})
TrackingService::Event.new(@user, @user.market, 'sample_items', "request_review_email #{@sample_item.id}").call()
end
ruby文档中没有立即明确的是,您需要返回邮件函数,而不仅仅是执行它。如果在构建邮件对象后需要执行某些操作,请确保在最后返回邮件。像这样:
def my_mail(foo)
m = mail(
to: to,
from: from,
subject: @sample_item.campaign_market.campaign.translation_for(language_id, 'sample_item_mailer.request_review.subject'),
content_type: "text/html"
)
@sample_item.update_attributes!({feedback_requested: true, review_requested_at: Time.now})
TrackingService::Event.new(@user, @user.market, 'sample_items', "request_review_email #{@sample_item.id}").call()
return m
end
def my_mail(foo)
m = mail(
to: to,
from: from,
subject: @sample_item.campaign_market.campaign.translation_for(language_id, 'sample_item_mailer.request_review.subject'),
content_type: "text/html"
)
@sample_item.update_attributes!({feedback_requested: true, review_requested_at: Time.now})
TrackingService::Event.new(@user, @user.market, 'sample_items', "request_review_email #{@sample_item.id}").call()
return m
end