我有以下 html 文件:
<html>
<head>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"description": "Click to view request details",
"potentialAction": {
"@type": "ViewAction",
"target": "<?= detailsurl ?>",
"name": "View request details"
}
}
</script>
</head>
<body>
<p>
<?= emailbody ?>
</p>
</body>
</html>
以及我的脚本中的以下函数:
function SendRichEmail(ToEmail,EmailSubject,detailsurl,emailbody) {
var templatefile = HtmlService.createTemplateFromFile('mail_template.html');
Logger.log(templatefile);
templatefile.detailsurl = detailsurl;
templatefile.emailbody = emailbody;
Logger.log(templatefile);
htmlBody = templatefile.evaluate();
Logger.log(htmlBody);
MailApp.sendEmail({
to: ToEmail,
subject: EmailSubject,
htmlBody: htmlBody,
name: "Support",
noReply: true
});
}
但是当它被触发时,我收到的电子邮件只是字符串“HTMLOutput”,当我检查日志时我得到这个:
[16-05-10 11:46:02:727 EAT] {}
[16-05-10 11:46:02:728 EAT] {detailsurl=http://www.correcturl.com/, emailbody=yada yada yada
[16-05-10 11:46:02:734 EAT] HtmlOutput
我被难住了。我假设问题出在阅读或评估模板上,但我无法查明它。感谢您的帮助。
最佳答案
正如我所怀疑的,这是一个愚蠢的疏忽。我传递的是一个对象而不是字符串。通过更改以下行解决:
htmlBody = templatefile.evaluate();
对此:
htmlBody = templatefile.evaluate().getContent();
现在可以完美运行了。
关于javascript - HTML 电子邮件消息显示为 "HtmlOutput",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37133554/