Class: Fyi::Notifier::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/fyi/notifiers/email.rb

Overview

Emails the results of command execution via SMTP.

By default only failures are emailed.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Email

Options you may supply:

from: the from address to: the to address on_success: whether to notify when the command succeeded.

Optional.  Defaults to false.

on_failure: whether to notify when the command failed.

Optional.  Defaults to true.

smtp: you should supply SMTP config options under this key.

SMTP config options are whatever Mail takes. github.com/mikel/mail/blob/master/lib/mail/network/delivery_methods/smtp.rb



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fyi/notifiers/email.rb', line 22

def initialize options
  @from = options['from']
  @to   = options['to']
  @on_success = options['on_success']
  # Notify of failures by default.
  @on_failure = options.has_key?('on_failure') ? options['on_failure'] : true

  smtp = symbolize_keys(options['smtp'])
  Mail.defaults do
    delivery_method :smtp, smtp
  end
end

Instance Method Details

#notify(command, result, duration, output, error = '', host = '') ⇒ Object



35
36
37
# File 'lib/fyi/notifiers/email.rb', line 35

def notify command, result, duration, output, error = '', host = ''
  send_email(command, result, duration, output, error, host) if should_notify?(result)
end