Class: SendGridActionMailer::DeliveryMethod
- Inherits:
-
Object
- Object
- SendGridActionMailer::DeliveryMethod
- 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
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(**params) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(**params) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
18 19 20 |
# File 'lib/sendgrid_actionmailer.rb', line 18 def initialize(**params) self.settings = DEFAULTS.merge(params) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
16 17 18 |
# File 'lib/sendgrid_actionmailer.rb', line 16 def api_key @api_key end |
#settings ⇒ Object
Returns the value of attribute settings.
16 17 18 |
# File 'lib/sendgrid_actionmailer.rb', line 16 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sendgrid_actionmailer.rb', line 22 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 || "" # https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html m.add_personalization(to_personalizations(mail)) end add_api_key(sendgrid_mail, mail) add_content(sendgrid_mail, mail) (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 |