【发布时间】:2018-02-03 15:28:16
【问题描述】:
我正在使用 Google Apps 脚本 (http://script.google.com) 为 gmail 编写一个自动回复机器人。每次用GmailThread的Reply回复消息:
var htmlbody = "Hello<br>This is a <b>test</b>.<br>Bye.";
var body = "Hello,\nThis is a test.\nBye.";
thread.reply(body, {htmlBody: htmlbody, from: "Myself <hello@example.com>"});
我需要用纯文本body 和htmlbody 中的HTML 编写消息。
有没有办法只用 HTML 编写电子邮件(避免将每封电子邮件的内容写两次,纯 HTML 和 HTML!),让reply() 自动发送电子邮件在 HTML 和纯文本版本中?
我试过了
var body = htmlbody.replace(/<br>/g,'\n').replace(/<b>/g,'');
// we should also replace </b> by '', etc.
但这有点小题大做。有更好的版本吗?
【问题讨论】:
标签: javascript html google-apps-script gmail gmail-api