Method: MultiMail::Message::SendGrid#to_sendgrid_hash

Defined in:
lib/multi_mail/sendgrid/message.rb

#to_sendgrid_hashHash

Returns the message as parameters to POST to SendGrid.

Returns:

  • (Hash)

    the message as parameters to POST to SendGrid



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/multi_mail/sendgrid/message.rb', line 51

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