提问人:Christi K 提问时间:11/4/2023 更新时间:11/4/2023 访问量:22
将变量从 Apps 脚本 code.gs 传递到 HTML 模板
Passing Variable from Apps Script code.gs to HTML template
问:
我正在尝试在学生更改为“待处理”时发送 HTMl 电子邮件。我可以使用未替换变量的 HTML 模板发送电子邮件,然后是脚本中替换变量的 htmlBody。如何获取要替换 html 模板中的变量?我是新来的,知道足够危险。
code.gs 是
function onPendingEdit(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//Event Variables
var range = e.range;
var row = e.range.getRow();
var col = e.range.getColumn();
var cellValue = sheet.getActiveCell().getValue();
var parentEmail = sheet.getRange(row,30).getValue();
var studentEmail = sheet.getRange(row,12).getValue();
var studentFirstName = sheet.getRange(row,9).getValue();
var studentLastName = sheet.getRange(row,10).getValue();
var team1 = sheet.getRange(row,3).getValue();
var team2 = sheet.getRange(row,4).getValue();
var team3 = sheet.getRange(row,5).getValue();
var recipient = studentEmail + (',') + parentEmail;
// get HTML template file
//var template = HtmlService.createTemplateFromFile('pendingEmail');
var template = HtmlService.createHtmlOutputFromFile('pendingEmail').getContent();
// set the values for the placeholders
template.parentEmail = sheet.getRange(row,30).getValue();
template.studentEmail = sheet.getRange(row,12).getValue();
template.studentFirstName = studentFirstName;
template.studentLastName = studentLastName;
if ( col == 2 && cellValue == "Pending"){
MailApp.sendEmail({
to: recipient,
subject: "Your application is pending. Next Steps.",
// body: "Changed to Pending." + parentEmail + studentEmail + studentFirstName + studentLastName + team1 + team2 + team3,
htmlBody: template + "<P>Your application is pending! Hello " + studentFirstName + studentLastName + "Congrats! Your application is pending! Welcome aboard, " + studentFirstName + ". You have been added to team " + team1 + " " + team2 + " " + team3 + " " + "pending the following steps: 1. Register with FIRST and accept the 2024 FIRST Consent and Release Form. Detailed instructions can be found here. https://www.firstinspires.org/resource-library/youth-registration-system 2. Waiver for FIRST in TX 3. Review our Saftey Manual 4. Sign our Shop Rules. 5. Have your parent contact Charlie to pay dues or agree to a payment plan.",
});
Browser.msgBox('An email has been sent to: ' + recipient);
};
}
此电子邮件中的结果。前半部分是适当的 HTML,没有变量。下半部分变量,没有HTMl。
您的申请正在等待中!
你好
恭喜!您的申请正在等待中!
欢迎加入,.
您已被添加到团队中,等待以下步骤:
在 FIRST 注册并接受 2024 FIRST 同意和释放表。详细说明可以在这里找到。https://www.firstinspires.org/resource-library/youth-registration-system
德克萨斯州 FIRST 的豁免
查看我们的 Saftey 手册
签署我们的商店规则。
让您的父母联系查理支付会费或同意付款计划。
您的申请正在等待中!你好JaneDoe恭喜!您的申请正在等待中!欢迎加入,Jane。您已被添加到团队 6369 中,等待以下步骤: 1. 在 FIRST 注册并接受 2024 FIRST 同意和释放表。详细说明可以在这里找到。https://www.firstinspires.org/resource-library/youth-registration-system2. 放弃德克萨斯州的 FIRST 3.查看我们的安全手册 4.签署我们的商店规则。5. 让您的父母联系查理支付会费或同意付款计划。
答: 暂无答案
评论