Why does the GMail API strip the doctype and comme

2020-06-23 06:57发布

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: bradvogel@outlook.com\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 bradvogel@outlook.com, it comes through without the doctype or comments:

To: bradvogel@outlook.com
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: bradvogel@outlook.com
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?

标签: gmail-api
1条回答
一夜七次
2楼-- · 2020-06-23 07:09

This is likely just an API design decision. Filed in their issue tracker as https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3786&thanks=3786&ts=1427478929

查看更多
登录 后发表回答