代码已基本完成,但我想在主题中包含今天的日期。为了实现这个目标,我必须在“const subject”中添加什么?我已经将今天的日期定义为“今天”
代码在图片中,请查看突出显示的部分
function sendEmails() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const dataRange = sheet.getRange("A17:dm");
const data = dataRange.getValues();
i=0; //i & j is the row number (up/down)
j=3;
const col = data[j];
const row = data[i];
const machinetype = row[84]; //the 84 is how far you are going to the right, add 4 to each when re-running it
const machinemodel = col[84];
const emailAddress = "[email protected]";
const subject = "New Machine";
const message = createEmailMessage(machinetype, machinemodel);
function createEmailMessage(machinetype, machinemodel) {
const message = `Hi Dhariana,
A new machine has arrived at the shop. It is a ${machinemodel}... a ${machinetype} machine.
Kindly schedule the cleaning procedure.
Thank you.
Best,
`;
return message;
}
try {
MailApp.sendEmail(emailAddress, subject, message);
console.log(` Email sent to ${emailAddress}`);
console.log(`${machinetype}, ${machinemodel}`);
} catch (error) {
}
}
由于您的
today
变量已经是一个字符串,因为 Utilities.formatDate() (见下图),您可以使用以下方式轻松地将其附加到字符串(您的主题):
使用
+
符号
const subject = "New machine "+today
或
使用
String literals
const subject = `New Machine ${today}`
today
变量的数据类型
示例输出