我正在寻找一种方法来让单元格标记电子邮件是否从 Google 表格发送。例如,如果电子邮件已发送,则会在该行的 P 列中显示“电子邮件已发送”或类似内容。我对此很陌生,我发现了一些有用的类似问题,但我只是不知道如何设置它。我想我需要使用 IF 命令,但不知道如何或在哪里设置它
function SendStudentEmails() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Homework Hour").activate();//use name of active sheet
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DO NOT DELETE! Parent Email Template").getRange(1, 1).getValue();
var quotaLeft = MailApp.getRemainingDailyQuota();
if((lr-1) > quotaLeft) {
Browser.msgBox("You have " + quotaLeft + " left and you're trying to send" (lr-1) + " emails. Emails were not sent")
} else {
for (var i = 2;i<=lr;i++){
var currentEmail = ss.getRange(i,14).getValue(); // 15 is the email column
var currentStudent = ss.getRange(i, 4).getValue(); // 4 is student name column
var currentMessage = ss.getRange(i, 2).getValue(); // 2 is the message column
var currentMissingAssingment = ss.getRange(i, 9).getValue(); // 9 is the missing assingment column
var massageBody = templateText.replace("<<Student Name>>",currentStudent).replace("<<Message>>",currentMessage).replace("<<Missing Assingment>>",currentMissingAssingment);
var subjectLine = currentStudent +" Has Homework Hour";
if (currentEmail.trim() !== '')// checks if email is not blank
MailApp.sendEmail(currentEmail, currentStudent, massageBody);
}
}
}
最佳答案
我是新手,但希望这对您有所帮助! 听起来您想在已发送电子邮件的每一行旁边进行标记,在这种情况下,您已经有了 if/for 案例设置来执行此操作(除了您似乎缺少一组最后一个 if 测试的大括号,如下)。您可以在电子邮件发送后将您想要的任何文本添加到该行的 P 列中。以下是代码部分,其中添加了将文本添加到 P 列的部分:
if (currentEmail.trim() !== '')// checks if email is not blank {
MailApp.sendEmail(currentEmail, currentStudent, massageBody);
ss.getRange(i,16).setValue("email sent") // writes text (email sent) into column P (col 16), row i (the current row in the for loop)
}
}
关于javascript - 每次发送电子邮件时如何标记每行中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59973046/