Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send email when exception has occurred not working , using exception_notification

I am migrating from rails 2.3 to rails 3.1, I am trying to send a email when exception is generated. I am using exception_notification gem.

My rest of the emails are working. But exception mail is not getting fired.

below are the settings in my staging.rb file.

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

and following is the code in application.rb

C::Application.config.middleware.use ExceptionNotification::Rack,
  :email => {
    :email_prefix => "[#{Rails.env.to_s.upcase} Error] ",
    :sender_address => %{"Exception Notifier " <email_id>},
    :exception_recipients => %w{email_id}
  }

I am not sure why the email is not triggering, nor do i see any error. Any help would be appriciated, Thanks.

like image 327
opensource-developer Avatar asked Aug 20 '15 12:08

opensource-developer


2 Answers

You need to configure your app like this:

C::Application.config.middleware.use ExceptionNotification::Rack,
  :email_prefix => "[#{Rails.env.to_s.upcase} Error] ",
  :sender_address => %{"Exception Notifier " <email_id>},
  :exception_recipients => %w{email_id}

Note You have excesive :email => {...} declaration which is used in configuration for exception_notifier version 4 (see here). But you can't use version 4 of exception_notifier with rails 3.1.

I created a repository at github https://github.com/dimakura/stackoverflow-projects/tree/master/32118817-exception-notification, which is a working example. I used ruby 1.9.3, rails 3.1.12 and exception_notifier 3.0.1. I guess you are using the same gems or close to it.

Note 2 When I added email: {...} to the configuration, exception messages stop to arrive.

like image 145
dimakura Avatar answered Nov 18 '22 18:11

dimakura


move the gem configuration code to the environment.rb file, instead of application.rb

like image 1
Sebastian Martinez Avatar answered Nov 18 '22 18:11

Sebastian Martinez