我有以下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吃] {}
[16-05-10 11:46:02:728吃]
{detailsurl = http://www.correcturl.com/,电子邮件正文= yada yada yada
[16-05-10 11:46:02:734 EAT] HtmlOutput
我很沮丧我假设问题在于阅读或评估模板,但我无法查明。感谢帮助。
最佳答案
我怀疑这是一个愚蠢的疏忽。我传递的是对象而不是字符串。通过更改以下行来解决:
htmlBody = templatefile.evaluate();
对此:
htmlBody = templatefile.evaluate().getContent();
现在,它可以完美运行了。