From f23a3fa69d7146a5e18da9eb3148b810b3c91d1d Mon Sep 17 00:00:00 2001 From: Hengjie Date: Wed, 5 Sep 2018 16:58:33 +1200 Subject: [PATCH] Retain formatted email address in sendouts The interceptor calls 'mail.to' to retrieve the email address. However, the mail gem will only return the address, and not the full formatted string. We can call `.addrs` (https://github.com/mikel/mail/blob/master/lib/mail/fields/common_address_field.rb#L47) but there's no easy way to access it. By removing all of this, we don't mangle the to/cc/bcc fields, and instead pass it straight through to Sendgrid which will handle it correctly. This also fixes a bug where bcc and cc aren't treated like they say, and are converted to 'To' addresses. This also removes the 'dummy_recipient' which has shown to be flagged as spam by GMail. --- lib/send_grid/mail_interceptor.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/send_grid/mail_interceptor.rb b/lib/send_grid/mail_interceptor.rb index 9a3aa79..acbecda 100644 --- a/lib/send_grid/mail_interceptor.rb +++ b/lib/send_grid/mail_interceptor.rb @@ -2,11 +2,7 @@ module SendGrid class MailInterceptor def self.delivering_email(mail) sendgrid_header = mail.instance_variable_get(:@sendgrid_header) - sendgrid_header.add_recipients(mail.to) - sendgrid_header.add_recipients(mail.cc) - sendgrid_header.add_recipients(mail.bcc) mail.header['X-SMTPAPI'] = sendgrid_header.to_json if sendgrid_header.data.present? - mail.header['to'] = SendGrid.config.dummy_recipient end end end