html - Google Apps Script not picking up HTML formatting in template
问题描述
I'm trying to clean up my code and decided to create a template for the emails rather than having it in the body of the code itself. A simplified version of my code looks like this:
function emailTest() {
var templ = HtmlService.createTemplateFromFile('testSLTMail');
templ.name = "Fazila";
templ.student = "Student1";
templ.oldClass = "classA";
templ.newClass = "classB";
templ.sltName = "Fazila";
templ.changeReason = "testing";
var message = templ.evaluate().getContent();
GmailApp.sendEmail('f.yunus@littleilford.org','Test Email', message);
And my HTML template looks like this:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p> Dear <?= sltName ?> </p>
<p> <?= name ?> has requested a change to the following student's timetable: </p>
<p><center><?= student ?>'s timetable from <strong><?= oldClass ?></strong> to <strong><?= newClass ?></strong></center></p>
<p> The reason for this change request is: </p>
<p><center><?= changeReason ?></center></p>
<p> Please confirm this request is authorised below. </p>
<p> Kind regards </p>
<p> Fazila </p>
</body>
</html>
However, when I get the email none of the HTML formatting is going through the email I get looks like this:
<p> Dear Fazila </p> <p> Fazila has requested a change to the following student's timetable: </p> <p><center>Student1's timetable from <strong>classA</strong> to <strong>classB</strong></center></p> <p> The reason for this change request is: </p> <p><center>testing</center></p> <p> Please confirm this request is authorised below. </p> <p> Kind regards </p> <p> Fazila </p>
I'm obviously missing a step somewhere which tells the apps script to apply the HTML formatting but can't see where. Any ideas?
Thanks
解决方案
使用此电子邮件构造函数:
MailApp.sendEmail({
to: "f.yunus@littleilford.org",
subject: "test",
htmlBody: message
});
有用!
推荐阅读
- c++ - 将一个类'对象设置为另一个类'方法
- android - :app:assembleRelease 和 assembleRelease 之间的区别
- javascript - 如何遍历两个数组的对象作为JavaScript中的以下输出
- reactjs - 不能用仅从 Github 获取的内容创建博客吗?
- java - 如果存在,则在 java 8 中使用反射器设置字段值
- sql - oracle查询从表中获取过去n(例如过去7)小时的每小时唯一用户计数
- java - 是否可以使用 JFR 和 JMC(JDK 任务控制)可视化每个线程的 cpu 使用情况?
- r - r 中的阻塞时间列取决于小时间隔
- php - 如何一起调用 JSON 多个数组函数?
- oracle - SQL*Plus 脚本执行了两次