Search code examples
ruby-on-railsruby-on-rails-3exception-notificationexception-notifier

ActionMailer::Base::NullMail when trying exception_notification in development


I'd like to add the exception_notification gem to our app, however, this happens when I try to manually trigger a mail:

exception
# => #<ZeroDivisionError: divided by 0>
ExceptionNotifier::Notifier.exception_notification(request.env, exception)
# => #<ActionMailer::Base::NullMail:0x007fa81bc7c610>
ExceptionNotifier::Notifier.background_exception_notification(exception)
# => #<ActionMailer::Base::NullMail:0x007fa81bf58190>

In the above example, the console is at a breakpoint inside rescue_from Exception in the ApplicationController after a deliberate 1/0 in some controller.

I'm using delayed_job as well, but - no surprise - ExceptionNotifier::Notifier.background_exception_notification(exception).deliver does not spool anything.

I've already set config.consider_all_requests_local = false in development, but still exception_notification instantiates NullMail. In other parts of the app, mailers work just fine and use sendmail.

Any ideas what I'm doing wrong here? Thanks for your help!


Solution

  • Likely you are using an old version of the ExceptionNotifier and a newer version of ActiveMailer::Base. Not calling the mail command within the email functionality will result in the ActionMailer::Base::NullMail instance returned rather than a Mail instance.

    From documentation:

    class Notifier < ActionMailer::Base
      default :from => '[email protected]',
             :return_path => '[email protected]'
    
      def welcome(recipient)
        @account = recipient
        mail(:to => recipient.email_address_with_name,
             :bcc => ["[email protected]", "Order Watcher <[email protected]>"])
      end
    end