我想用工作表中特定的静态单元格的内容填充电子邮件

I would like to populate an email message with the contents of a specific, static, cell in sheets

当有人在 Google 表格上注册预约时,我会发送一封确认电子邮件。我想用特定单元格的内容填充电子邮件。这意味着我可以在单元格 A2 中输入电子邮件消息,当有人填写表格时,它会将该消息作为确认电子邮件发送给他们。

我正在使用两封不同的电子邮件,确认邮件和提醒邮件。我希望这两个代码都填充相同的消息。

function confirmationEmail(e) {
   var userName = e.values[2];
   var userEmail = e.values[3] + ";user@gmail.com";
   var date = e.values[4];
   var studentName = e.values[1];
   var body1 = "Hello " + userName + ",";
   var body2 = studentName + " has been registered for a physical at High School for the following date/time:";
   var body3 = "Please park in the large student parking lot on the east side of the High School.";
   var body4 = "Thanks!";
   var signature = "Name" + "\n" + "High School" + "\n" + "user@gmail.com" + "\n" + "***-***-****";
   var file1 = DriveApp.getFilebyId("1WDxic1meHzEGSjybJ2SS1h2MqGAhIAK4");
   var file2 = DriveApp.getFilebyId("1v4GQAP8PkTPQRPoYIdsEOMBr2ZvRO1eocsqixyZ42gA");


GmailApp.sendEmail(userEmail, 
                     "Registration",
                     body1 + "\n\n" + body2 +"\n\n" + date + "\n\n" + body3 + "\n\n" + body4 + "\n\n" + signature,
                     {attachments:[file1, file2]})

}

这段代码已经可以完美运行了,但是,我有一些同事甚至比我还不精明。如果他们可以只在单元格中填写消息内容以便能够发送出去,那就最好了.所以理想情况下,"body3" 将被写入工作表中的单元格并填充到电子邮件中。

所以我猜你会想要这样的东西:

var body3 = SpreadsheetApp.getActiveSheet().getRange('A2').getValue();

您可能应该在代码中包含一些条件语句,以防止在单元格 'A2' 为空的情况下发送电子邮件,并包含一个警告以通知用户需要填写它。

也许是这样的:

if(body1 && body2 && body3){
  //send email
}else{
  SpreadsheetApp.getUi().alert('Invalid or Missing Content');
}