Class: Broadcast::Medium::Email

Inherits:
Broadcast::Medium show all
Defined in:
lib/broadcast/media/email.rb

Instance Method Summary collapse

Methods inherited from Broadcast::Medium

#initialize, #namespace, #options

Constructor Details

This class inherits a constructor from Broadcast::Medium

Instance Method Details

#publish(message) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/broadcast/media/email.rb', line 5

def publish(message)
  recipients = options.recipients.is_a?(Array) ? options.recipients : [options.recipients]
  options = self.options
  recipients.compact.each do |recipient|
    mail = Mail.new do
       from    options.sender || message.class.to_s
       to      recipient
       subject message.subject || message.class.to_s
       body    message.body
    end
    if options.delivery_method
      # ensure the delivery options has symbolized keys
      # Addresses https://github.com/futuresimple/broadcast/issues/9
      delivery_options = options.delivery_options.inject({}) do |memo, setting|
        memo[setting[0].to_s.to_sym] = setting[1]
        memo
      end
      mail.delivery_method options.delivery_method, delivery_options || {}
    end
    mail.deliver
  end
end