How to send custom email in exception notification?

1.1k Views Asked by At

I have used exception notification gem to send exceptions to email, the email contains lots of data I want to minimize the data for e.g I don't want to send Environment details

    ------------------------------
     Environment:
    -------------------------------

Is there any way skip environment details on the exception mail?

1

There are 1 best solutions below

0
On

You can customize the sections. Read the documentation on github. There they said we can customize.

By default, the notification email includes four parts: request, session, environment, and backtrace (in that order). You can customize how each of those sections are rendered by placing a partial named for that part in your app/views/exception_notifier directory (e.g., _session.rhtml).

You can reorder the sections, or exclude sections completely, by using sections option. You can even add new sections that describe application-specific data--just add the section's name to the list (wherever you'd like), and define the corresponding partial. Like the following example with two new added sections:

  Rails.application.config.middleware.use ExceptionNotification::Rack,
   :email => {
   :email_prefix => "[PREFIX] ",
   :sender_address => %{"notifier" <[email protected]>},
   :exception_recipients => %w{[email protected]},
   :sections => %w{my_section1 my_section2}
}

Place your custom sections under ./app/views/exception_notifier/ with the suffix .text.erb, e.g. ./app/views/exception_notifier/_my_section1.text.erb.