4
votes

The Gmail Message Send API appears to be stripping out doctype and HTML comments from outgoing messages.

Repro

  1. Go to https://developers.google.com/gmail/api/v1/reference/users/messages/send
  2. Scroll down to "Try it!"
  3. Log in with OAuth
  4. For "userId" enter: me
  5. For "raw" enter the result of the following node script:

generateMessage.js

var email = "From: 'me'\r\n" +
  "To: [email protected]\r\n" +
  "Subject: Test Doctype\r\n" +
  "Content-Type: text/html; charset=utf-8\r\n" +
  "\r\n" +
  "<!doctype html>" +
  "<html><body>test <!--[if !mso]>hidden from outlook<!--<![endif]--> </body></html>";

var base64 = new Buffer(email).toString('base64');
var websafeBase64 = base64.replace(/\//g, '_').replace(/\+/g, '-');
console.log(websafeBase64);

Actual result

When I view the raw message source from the email received at [email protected], it comes through without the doctype or comments:

To: [email protected]
Subject: Test Doctype
Content-Type: multipart/alternative; boundary=089e0102fc52abed0a04ff355038

--089e0102fc52abed0a04ff355038
Content-Type: text/plain; charset=UTF-8

test

--089e0102fc52abed0a04ff355038
Content-Type: text/html; charset=UTF-8

<html><body>test  </body></html>

--089e0102fc52abed0a04ff355038--

Expected result

Notice the doctype below:

To: [email protected]
Subject: Test Doctype
Content-Type: multipart/alternative; boundary=089e0102fc52abed0a04ff355038

--089e0102fc52abed0a04ff355038
Content-Type: text/plain; charset=UTF-8

test

--089e0102fc52abed0a04ff355038
Content-Type: text/html; charset=UTF-8

<!doctype html>
<html><body>test <!--[if !mso]>hidden from outlook<!--<![endif]--> </body></html>

--089e0102fc52abed0a04ff355038--

Notes

Sending the same message via SMTP preserves the entire message.

The doctype and comments are needed to format emails for Outlook and iOS Mail. The API appears to be taking my raw rfc822 message and converting it multipart/alternative with text and html representations, but with important content stripped out.

Does anyone know how to preserve doctype and comments in a message send through the Gmail Message Send api?

1
To add a bit more detail to Brad's question: not having doctype in the HTML email, causes iOS Mail to display the email in "Almost Standards" mode, which is like "Quirks Mode" rendering in old IE browsers. The only way I can find to trigger the "Standards" mode is to include a doctype, which is strangely stripped out when sending emails via the Gmail API.Chanpory
What is gmailclient in this instance? Being able to run this locally would help.loganfsmyth
Logan, updated the repro steps to be clearer. Thanks ;).Brad Vogel
I reached out to the engineering team for more information on whether this behavior is intentional or not.Eric Koleda
@BradVogel Hi, could you please post the code which sends the email? I'm having an issue connected to yours and I would like to see how you are sending it. Thx in advance!Eduárd Moldován

1 Answers

4
votes