Gmail邮件发送 API似乎正在从外发邮件中删除 doctype 和 HTML 注释。
复制品
- 转到https://developers.google.com/gmail/api/v1/reference/users/messages/send
- 向下滚动到“试试看!”
- 使用 OAuth 登录
- 对于“userId”,输入:我
- 对于“原始”,输入以下节点脚本的结果:
生成消息.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);
实际结果
当我从 bradvogel@outlook.com 收到的电子邮件中查看原始消息源时,它没有 doctype 或评论:
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--
预期结果
注意下面的文档类型:
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--
笔记
通过 SMTP 发送相同的邮件会保留整个邮件。
需要文档类型和注释来格式化 Outlook 和 iOS 邮件的电子邮件。API 似乎正在获取我的原始 rfc822 消息并将其转换为带有文本和 html 表示的多部分/替代,但删除了重要内容。
有谁知道如何在通过 Gmail Message Send api 发送的消息中保留文档类型和评论?