The Gmail Message Send API appears to be stripping out doctype and HTML comments from outgoing messages.
Repro
- Go to https://developers.google.com/gmail/api/v1/reference/users/messages/send
- Scroll down to "Try it!"
- Log in with OAuth
- For "userId" enter: me
- 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?
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