lib/sendgrid_actionmailer.rb in sendgrid-actionmailer-2.5.0 vs lib/sendgrid_actionmailer.rb in sendgrid-actionmailer-2.6.0

- old
+ new

@@ -144,21 +144,31 @@ if mail['delivery-method-options'] && mail['delivery-method-options'].value.include?('api_key') self.api_key = JSON.parse(mail['delivery-method-options'].value.gsub('=>', ':'))['api_key'] end end + def add_attachments(sendgrid_mail, mail) + mail.attachments.each do |part| + sendgrid_mail.add_attachment(to_attachment(part)) + end + end + def add_content(sendgrid_mail, mail) - case mail.mime_type - when 'text/plain' - sendgrid_mail.add_content(to_content(:plain, mail.body.decoded)) - when 'text/html' - sendgrid_mail.add_content(to_content(:html, mail.body.decoded)) - when 'multipart/alternative', 'multipart/mixed', 'multipart/related' - sendgrid_mail.add_content(to_content(:plain, mail.text_part.decoded)) if mail.text_part - sendgrid_mail.add_content(to_content(:html, mail.html_part.decoded)) if mail.html_part + if mail['template_id'] + # We are sending a template, so we don't need to add any content outside + # of attachments + add_attachments(sendgrid_mail, mail) + else + case mail.mime_type + when 'text/plain' + sendgrid_mail.add_content(to_content(:plain, mail.body.decoded)) + when 'text/html' + sendgrid_mail.add_content(to_content(:html, mail.body.decoded)) + when 'multipart/alternative', 'multipart/mixed', 'multipart/related' + sendgrid_mail.add_content(to_content(:plain, mail.text_part.decoded)) if mail.text_part + sendgrid_mail.add_content(to_content(:html, mail.html_part.decoded)) if mail.html_part - mail.attachments.each do |part| - sendgrid_mail.add_attachment(to_attachment(part)) + add_attachments(sendgrid_mail, mail) end end end def json_parse(text, symbolize=true)