Why does the GMail API strip the doctype and comments from outgoing messages?

可紊 提交于 2019-12-21 05:39:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/24979403/why-does-the-gmail-api-strip-the-doctype-and-comments-from-outgoing-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!