Class: EmailDirect::Mailer
- Inherits:
-
Object
- Object
- EmailDirect::Mailer
- Defined in:
- lib/emaildirect/mailer.rb
Overview
Implements a Mailer class that can be used by Mail to send using the relay functionality
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(values = {}) ⇒ Mailer
constructor
A new instance of Mailer.
- #new(*args) ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ Mailer
Returns a new instance of Mailer.
6 7 8 9 10 11 12 13 |
# File 'lib/emaildirect/mailer.rb', line 6 def initialize(values = {}) self.settings = { :category_id => nil, :options => {}, :logger => defined?(::Rails) && ::Rails.logger, :log_level => :debug }.merge!(values) raise ArgumentError, 'Category ID is required' unless settings[:category_id] end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
15 16 17 |
# File 'lib/emaildirect/mailer.rb', line 15 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/emaildirect/mailer.rb', line 21 def deliver!(mail) destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations if destinations.blank? raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message') end = request_data mail # Can only send to a max of 50 addresses at a time destinations.each_slice(50).each do |destination_slice| [:Recipients] = [] destination_slice.each do |destination| [:Recipients] << { :ToEmail => destination } end response = RelaySend::Email.new(settings[:category_id]).send() settings[:logger].send(settings[:log_level], "EmailDirect: #{response.inspect}") if settings[:logger] end end |
#new(*args) ⇒ Object
17 18 19 |
# File 'lib/emaildirect/mailer.rb', line 17 def new(*args) self end |