Class: MultiMail::Message::SendGrid
- Defined in:
- lib/multi_mail/sendgrid/message.rb
Overview
Instance Attribute Summary collapse
-
#dkim ⇒ Object
Returns the value of attribute dkim.
-
#spam_report ⇒ Object
Returns the value of attribute spam_report.
-
#spam_score ⇒ Object
Returns the value of attribute spam_score.
-
#spf ⇒ Object
Returns the value of attribute spf.
Instance Method Summary collapse
-
#sendgrid_content ⇒ Hash
Returns the attachments' content IDs in SendGrid format.
-
#sendgrid_files ⇒ Hash
Returns the message's attachments in SendGrid format.
-
#sendgrid_headers ⇒ Hash
Returns the message headers in SendGrid format.
-
#to_sendgrid_hash ⇒ Hash
Returns the message as parameters to POST to SendGrid.
Constructor Details
This class inherits a constructor from MultiMail::Message::Base
Instance Attribute Details
#dkim ⇒ Object
Returns the value of attribute dkim.
5 6 7 |
# File 'lib/multi_mail/sendgrid/message.rb', line 5 def dkim @dkim end |
#spam_report ⇒ Object
Returns the value of attribute spam_report.
5 6 7 |
# File 'lib/multi_mail/sendgrid/message.rb', line 5 def spam_report @spam_report end |
#spam_score ⇒ Object
Returns the value of attribute spam_score.
5 6 7 |
# File 'lib/multi_mail/sendgrid/message.rb', line 5 def spam_score @spam_score end |
#spf ⇒ Object
Returns the value of attribute spf.
5 6 7 |
# File 'lib/multi_mail/sendgrid/message.rb', line 5 def spf @spf end |
Instance Method Details
#sendgrid_content ⇒ Hash
Returns the attachments' content IDs in SendGrid format.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/multi_mail/sendgrid/message.rb', line 38 def sendgrid_content hash = {} .each do || if .content_type.start_with?('image/') # Mirror Mailgun behavior for naming inline attachments. # @see http://documentation.mailgun.com/user_manual.html#inline-image hash[.filename] = .filename end end hash end |
#sendgrid_files ⇒ Hash
Returns the message's attachments in SendGrid format.
25 26 27 28 29 30 31 32 33 |
# File 'lib/multi_mail/sendgrid/message.rb', line 25 def sendgrid_files hash = {} .map do || # File contents must be part of the multipart HTTP POST. # @see http://sendgrid.com/docs/API_Reference/Web_API/mail.html hash[.filename] = Faraday::UploadIO.new(StringIO.new(.body.decoded), .content_type, .filename) end hash end |
#sendgrid_headers ⇒ Hash
Returns the message headers in SendGrid format.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/multi_mail/sendgrid/message.rb', line 10 def sendgrid_headers hash = {} header_fields.each do |field| key = field.name.downcase unless %w(to subject from bcc reply-to date).include?(key) # The JSON must not contain integers. hash[field.name] = field.value.to_s end end hash end |
#to_sendgrid_hash ⇒ Hash
Returns the message as parameters to POST to SendGrid.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/multi_mail/sendgrid/message.rb', line 53 def to_sendgrid_hash headers = sendgrid_headers hash = { 'to' => to.to_a, 'toname' => to && self[:to].display_names.to_a, 'subject' => subject, 'text' => body_text, 'html' => body_html, 'from' => from && from.first, 'bcc' => bcc.to_a, 'fromname' => from && self[:from].display_names.first, 'replyto' => reply_to && reply_to.first, 'date' => date && Time.parse(date.to_s).rfc2822, # Ruby 1.8.7 'files' => sendgrid_files, 'content' => sendgrid_content, 'headers' => headers.empty? ? nil : JSON.dump(headers), } normalize(hash) end |