简体   繁体   中英

Rails 4 - Exception notifier doesn't send email if error

I have a Rails 4 app and using the gem exception_notification . The gem is installed, in config/environments/production.rb is following:

  config.action_mailer.delivery_method = :sendmail
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

  config.middleware.use ExceptionNotification::Rack,
    :email => {
      :email_prefix => "[MyProj Error Report] ",
      :sender_address => %{"MyProj" <no-reply@myproj.com>},
      :exception_recipients => %w{info@myproj.com}
    }

no-reply@myproj.com email address doesn't exist, info@myproj.com is my real email address.

When an error will occur on production, I don't receive any email about it.

What other configuration information do I need to add?

EDIT: config/environments/production.rb :

Rails.application.configure do
  ...
  MyApp::Application.config.middleware.use ExceptionNotification::Rack,
    :email => {
      :email_prefix => "[MyApp_Error] ",
      :sender_address => %{"notifier" <notifier@myAppName.com>},
      :exception_recipients => %w{your_email_id@gmail.com}
    }
end

I modified the code with my real email addresses, but still no success. In log is nothing - when I want to fetched a record with a non-existing ID, like website.com/articles/123345666777 , in the error log is only the following:

ActiveRecord::RecordNotFound (Couldn't find Article with 'id'=123345666777):
  app/controllers/articles_controller.rb:175:in `set_article'

ActiveRecord::RecordNotFound is a very special case (same for routing errors and some others). I would be surprised if this kind of exceptions triggered the ExceptionNotifier to send mails. In a production environment, Rails would handle this error by rendering the 404 (not found) page, instead of a 500 (server error) that would happen if Rails couldn't handle the exception.

And in fact, there is the option ignore_exceptions in ExceptionNotifier that includes this exception by default. Read more about the ignore_exceptions option and its defaults .

try to use this...with the AppName like this:-

 MyAppName::Application.config.middleware.use ExceptionNotification::Rack,
   :email => {
     :email_prefix => "[MyApp_Error] ",
     :sender_address => %{"notifier" <notifier@myAppName.com>},
     :exception_recipients => %w{your_email_id@gmail.com}
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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