Class: SafetyMailer::Carrier

Inherits:
Object
  • Object
show all
Defined in:
lib/safety_mailer/safety_mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Carrier

Returns a new instance of Carrier.



5
6
7
8
9
10
11
# File 'lib/safety_mailer/safety_mailer.rb', line 5

def initialize(params = {})
  self.matchers = params[:allowed_matchers] || []
  self.settings = params[:delivery_method_settings] || {}
  delivery_method = params[:delivery_method] || :smtp
  @delivery_method = Mail::Configuration.instance.lookup_delivery_method(delivery_method).new(settings)
  @sendgrid_options = {}
end

Instance Attribute Details

#mailObject

Returns the value of attribute mail.



3
4
5
# File 'lib/safety_mailer/safety_mailer.rb', line 3

def mail
  @mail
end

#matchersObject

Returns the value of attribute matchers.



3
4
5
# File 'lib/safety_mailer/safety_mailer.rb', line 3

def matchers
  @matchers
end

#settingsObject

Returns the value of attribute settings.



3
4
5
# File 'lib/safety_mailer/safety_mailer.rb', line 3

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/safety_mailer/safety_mailer.rb', line 13

def deliver!(mail)
  self.mail = mail
  allowed = filter(recipients)

  if allowed.empty?
    log "*** safety_mailer - no allowed recipients ... suppressing delivery altogether"
    return
  end

  mail['X-SMTPAPI'].value = prepare_sendgrid_delivery(allowed) if sendgrid?
  mail.to = allowed

  @delivery_method.deliver!(mail)
end