Newlines allowed as = 0A in the Sendgrid X-SMTPAPI header

I use Sendgrid to send email to the mailing list using the X-SMTPAPI header to specify multiple recipients. From the sending documentation . Headers should be wrapped so that the line length does not exceed 72.

I use ActionMailer to send emails and set the X-SMTPAPI header using the method headers. To keep lines less than 72 characters, I tried replacing each comma with a comma + new line + space. For instance,

headers["X-SMTPAPI"] = {
        :to => ['user1@example.com','user2@example.com','user3@example.com','user4@example.com','user5@example.com','user6@example.com']
}.to_json.gsub(',',",\n ")

Instead of getting newlines in my header, I get the following (from the log file)

X-SMTPAPI: {"to":["user1@example.com",=0A "user2@example.com",=0A "user3@example.com",=0A "user4@example.com",=0A "user5@example.com",=0A "user6@example.com"]}

Note that the \ n characters are replaced with =0A. This sequence is rejected by the Sendgrid server as invalid.

Any ideas what I can do to get the correct newlines in the header?

Edit: I tried adding “puts headers” to see what is given in the headers. Then I found

Date: Sat, 13 Apr 2013 18:21:36 -0400
Message-ID: <5169da701cd26_5343fe1776afc50749b4@saunders.mail>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-SMTPAPI: {"to":["user1@example.com",=0A "user2@example.com",=0A
 "user3@example.com",=0A "user4@example.com",=0A "user5@example.com",=0A
 "user6@example.com"]}

Please note that the new lines that I am adding still display as "= 0A". But it looks like packaging is being added on its own. Is this automatic wrapping and sufficient to make my title bar length exceed the requirements?

+5
source share
2 answers

ActionMailer will actually handle folding and encoding strings for you if you give it the correct spacing for this. You must use JSON.generateto set the interval:

Ref.

headers["X-SMTPAPI"] = JSON.generate({
  :category => "welcome_email",
  :to => ['user1@example.com','user2@example.com','user3@example.com','user4@example.com','user5@example.com','user6@example.com']
}, :indent => ' ')

This will lead to:

X-SMTPAPI: { "category":"welcome_email", "to":[  "user1@example.com",
 "user2@example.com",  "user3@example.com",  "user4@example.com",  
 "user5@example.com",     "user6@example.com"]}

, ActionMailer , - \r\n.

+5

, RFC 2047 [14].
ASCII %0A \n

0

All Articles