简体   繁体   中英

How do i send an email using exception_notifier gem manually?

I am trying the following code:

ExceptionNotifier::Notifier.exception_notification(env, exception).deliver

But this message keep on appearing:

A sender (Return-Path, Sender or From) required to send a message

Any idea why this is happening and how I can get around it?

You likely have not configured the gem in an initializer. In my controller action for notifying me of an exception I have the following

ExceptionNotifier::Notifier.exception_notification(
  request.env, 
  env["action_dispatch.exception"]
).deliver

I have the following in config/initializers/exception_notifier.rb

if Rails.env.production?
  MyApp::Application.config.middleware.use ExceptionNotifier,
    email_prefix:         "[#{App.domain.pretty}] ",
    sender_address:       App.email.noreply,
    exception_recipients: App.email.exceptions,
    ignore_exceptions:    ExceptionNotifier.default_ignore_exceptions,
    normalize_subject:    true
end

MyApp , and App.____ should all be replaced by your own values.

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