简体   繁体   English

Rails 4 + Exception Notifier不会在开发模式下发送电子邮件

[英]Rails 4 + Exception Notifier doesn't send email in development mode

I am trying to test the Exception Notifier out locally (development). 我试图在本地测试Exception Notifier(开发)。 Here's my current setup: 这是我目前的设置:

development.rb

Myapp::Application.configure do
  # Set Mailer default url
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
  #config.action_mailer.delivery_method = :file
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
       :address              => 'smtp.gmail.com',
       :port                 => 587,
       :domain               => 'gmail.com',
       :user_name            => 'username@gmail.com',
       :password             => 'password',
       :authentication       => 'plain',
       :enable_starttls_auto => true
   }

  config.middleware.use ExceptionNotification::Rack,
    :email => {
      :email_prefix => "[Myapp Error] ",
      :sender_address => %{"notifier" <no-reply@myapp.com>},
      :exception_recipients => %w{myemail@gmail.com}
    }
end

But when I "create" an error in the application -- for example if I set up non-existing ID, like 但是当我在应用程序中“创建”错误时 - 例如,如果我设置了不存在的ID,例如

http://localhost:3000/users/12270/edit

I see only error in the browser, but the email is not sent out (email credentials are correct). 我在浏览器中只看到错误,但电子邮件未发送(电子邮件凭据正确)。

What do I miss? 我错过了什么?

Than you 比你

要在开发模式下禁用错误页面,您还需要设置:

config.consider_all_requests_local = false

ExceptionNotifier will send messages on a 500 error. ExceptionNotifier将发送500错误消息。 However, your test "...if I request a non-existing ID..." returns a 404 not found. 但是,您的测试“...如果我请求不存在的ID ...”则返回404未找到。 From the docs : 来自文档

Some rack apps (Rails in particular) utilize the "X-Cascade" header to pass the request-handling responsibility to the next middleware in the stack. 某些机架应用程序(特别是Rails)利用“X-Cascade”标头将请求处理职责传递给堆栈中的下一个中间件。

Rails' routing middleware uses this strategy, rather than raising an exception, to handle routing errors (eg 404s); Rails的路由中间件使用这种策略,而不是引发异常,来处理路由错误(例如404); to be notified whenever a 404 occurs, set this option to "false." 要在404发生时收到通知,请将此选项设置为“false”。

I normally use gem letter_opener for development environment. 我通常使用gem letter_opener来开发环境。

I think Exception Notifier doesn't send emails in development environment which is understandable as you are breaking all sort of things in development and getting errors for every one would be annoying. 我认为Exception Notifier不会在开发环境中发送电子邮件,这是可以理解的,因为你在开发中破坏所有类型的东西并且每个人都会遇到错误会很烦人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM