class Rusen::Notifiers::MailNotifier

Public Class Methods

identification_symbol() click to toggle source
# File lib/rusen/notifiers/mail_notifier.rb, line 18
def self.identification_symbol
  :mail
end
new(settings) click to toggle source
Calls superclass method Rusen::Notifiers::BaseNotifier::new
# File lib/rusen/notifiers/mail_notifier.rb, line 22
def initialize(settings)
  super(settings)

  if @settings && @settings.smtp_settings.any?
    smtp_settings = @settings.smtp_settings

    Mail.defaults do
      delivery_method :smtp, smtp_settings
    end
  end
end

Public Instance Methods

notify(notification) click to toggle source
# File lib/rusen/notifiers/mail_notifier.rb, line 34
def notify(notification)
  @notification = notification
  @sessions     = get_sessions(@notification)

  options = email_options.dup
  options.merge!({:body => build_body})
  mail = Mail.new do
    from      options[:from]
    to        options[:to]
    reply_to  options[:reply_to]
    cc        options[:cc]
    bcc       options[:bcc]
    subject   options[:subject]
    html_part do
      content_type "text/html; charset=#{options[:charset]}"
      body    options[:body]
    end
  end

  # We need to ignore all the exceptions thrown by MailNotifier#notify.
  mail.deliver!
rescue Exception => exception
  handle_notification_exception(exception)
end

Private Instance Methods

build_body() click to toggle source
# File lib/rusen/notifiers/mail_notifier.rb, line 74
def build_body
  template_path = File.expand_path('../../templates/email_template.html.erb', __FILE__)

  template = File.open(template_path).read
  rhtml = ERB.new(template, nil, '-')
  rhtml.result(binding)
end
email_options() click to toggle source
# File lib/rusen/notifiers/mail_notifier.rb, line 61
def email_options
  {
    :to => @settings.exception_recipients,
    :charset => 'UTF-8',
    :from => @settings.sender_address,
    :subject => email_subject
  }
end
email_subject() click to toggle source
# File lib/rusen/notifiers/mail_notifier.rb, line 70
def email_subject
  @settings.email_prefix + "#{@notification.exception.class}: #{@notification.exception.message}"
end