Skip to content

Override the Mailer Class

Sean C Davis edited this page Sep 5, 2016 · 1 revision

Email notifications use the NotifyOn::NotificationMailer class by default.

You may need to customize the default class for your application. You can do this by setting mailer_class in config/initializers/notify_on.rb.

Example: Access ApplicationHelper in Email Templates

This can come in handy even when you just need to do something really simple, like adding your ApplicationHelper's methods to your email templates.

First, you'd set your default mailer class (don't forget to restart the server):

NotifyOn.configure do |config|
  config.mailer_class = 'NotificationMailer'

  # ...
end

Then have your mailer inherit from NotifyOn::NotificationMailer and use super so you don't have to duplicate too much code.

class NotificationMailer < NotifyOn::NotificationMailer

  helper :application

  def notify(notification_id, template = 'notify')
    super
  end

end