Class: Outpost::Notifiers::Email

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

Overview

The Email notifier issues Outpost notifications to through email. It uses the 'mail' gem send the emails. You can see mail's documentation in order to change how emails will be delivered: github.com/mikel/mail

This requires the 'mail' gem to be installed.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Email

Returns a new instance of Email

Options Hash (options):

  • :from (String)

    The “from” email field

  • :to (String)

    Where e-mails will be delivered

  • :subject (String)

    The email's subject


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

def initialize(options={})
  @from    = options[:from]
  @to      = options[:to]
  @subject = options[:subject] || 'Outpost notification'
  @delivery_method = options[:delivery_method] || []

  unless @from && @to
    raise ArgumentError, 'You need to set :from and :to to send emails.'
  end
end

Instance Method Details

#notify(outpost) ⇒ Object

Issues a notification through email. This is a callback, called by an Outpost instance.


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/outpost/notifiers/email.rb', line 38

def notify(outpost)
  mail         = Mail.new
  mail.from    = @from
  mail.to      = @to
  mail.subject = @subject
  mail.body    = build_message(outpost)

  mail.send(:delivery_method, *@delivery_method) unless @delivery_method.empty?

  mail.deliver
end