Class: SendGridActionMailer::DeliveryMethod

Inherits:
Object
  • Object
show all
Includes:
SendGrid
Defined in:
lib/sendgrid_actionmailer.rb

Constant Summary collapse

SendgridDeliveryError =

TODO: use custom class to customer excpetion payload

Class.new(StandardError)
DEFAULTS =
{
  raise_delivery_errors: false
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ DeliveryMethod

Returns a new instance of DeliveryMethod.



19
20
21
# File 'lib/sendgrid_actionmailer.rb', line 19

def initialize(**params)
  self.settings = DEFAULTS.merge(params)
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



17
18
19
# File 'lib/sendgrid_actionmailer.rb', line 17

def api_key
  @api_key
end

#settingsObject

Returns the value of attribute settings.



17
18
19
# File 'lib/sendgrid_actionmailer.rb', line 17

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sendgrid_actionmailer.rb', line 23

def deliver!(mail)
  sendgrid_mail = Mail.new.tap do |m|
    m.from = to_email(mail.from)
    m.reply_to = to_email(mail.reply_to)
    m.subject = mail.subject || ""
  end

  add_personalizations(sendgrid_mail, mail)
  add_api_key(sendgrid_mail, mail)
  add_content(sendgrid_mail, mail)
  add_send_options(sendgrid_mail, mail)
  add_mail_settings(sendgrid_mail, mail)
  add_tracking_settings(sendgrid_mail, mail)

  response = perform_send_request(sendgrid_mail)

  settings[:return_response] ? response : self
end