ROR version
Ruby=>3.2.13
Rails=>1.9.3
Gemfile
Add below gems into your Gemfile
gem "mail"
gem "exception_notification",
:git => "git://github.com/rails/exception_notification.git",
:require => "exception_notifier"
if you going to run application in development mode
development.rb
config.action_mailer.raise_delivery_errors = true(default false so you must chang true)
add below two lines
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
application.rb(config/)
add below configuration into application.rb
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'test.com',
:user_name => 'notifier@gmail.com',
:password => 'xxxxxxx',
:authentication => :plain,
:enable_starttls_auto => true }
config.middleware.use ExceptionNotifier,
:email_prefix => "[myAppliction Error Report] ",
:sender_address => %{"notifier" <notifier@gmail.com>},
:exception_recipients => %w{gowthaman@gmail.com}
end
if you going to run application in production mode
production.rb
add below three lines
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
and add below configuration into production.rb
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'test.com',
:user_name => 'notifier@gmail.com',
:password => 'xxxxxxx',
:authentication => :plain,
:enable_starttls_auto => true }
config.middleware.use ExceptionNotifier,
:email_prefix => "[myAppliction Error Report] ",
:sender_address => %{"notifier" <notifier@gmail.com>},
:exception_recipients => %w{gowthaman@gmail.com}
end
If you want to send notifications from a background process like DelayedJob, you should use the notify_exception method like this:
begin
some code...
rescue => e
ExceptionNotifier.notify_exception(e)
end
Refer: gem exception_notification