javascript - HTML 电子邮件消息显示为 "HtmlOutput"

标签 javascript google-apps-script

我有以下 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/

相关文章:

multithreading - Google Apps 脚本和表格 : appendRow() regularly overwrites the last row instead of appending a new row below

google-apps-script - Apps 脚本驱动应用服务 - 创建 Google 类型 - Mime 类型的文件

javascript - 无法在 Chrome 浏览器中查看我的下拉菜单,但是当我在此处插入代码时,我可以查看它。怎么会?

javascript - 通过 WebPack 将 Bootstrap 加载到 Wordpress 时,ReactJS 代码拆分会导致错误

javascript - 错误:在 Ember.js 服务器上获取 http://localhost:4200/assets/vendor.js net::ERR_INVALID_CHUNKED_ENCODING

javascript - 我如何在 node.js 中显示渲染而不是 console.log

javascript - 在我的具体情况下,如何将 3 个盒子并排放置?

javascript - 创建条形图 - 添加行

javascript - 数组中的每个字符都被 javascript 中的 ".hasOwnProperty(i)"识别为 Google Apps 脚本的 true

google-apps-script - 如何在谷歌表格图表中获得多行副标题?