opensource-developer
opensource-developer

Reputation: 3068

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.

Upvotes: 6

Views: 1359

Answers (2)

dimakura
dimakura

Reputation: 7655

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.

Upvotes: 4

Sebastian Martinez
Sebastian Martinez

Reputation: 447

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

Upvotes: 1

Related Questions