我正在尝试向学生发送自动电子邮件,并提供有关课程工作的反馈。我开发了一种带有标记方案的google表单,在该表单中输入了学生编号,但脚本未读取命名值方法。
我试图逐一处理学生编号,其余的代码都起作用。
代码如下:
function sendNotification(e){
var s = SpreadsheetApp.getActiveSheet();
var message = "";
var headers =s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
message += "This automated email includes the marks and feedback for
your Main report Assignment.\n\n";
var studentNumber = e.namedValues[headers[3]].toString();
Logger.log("column 3: " + studentNumber);
message += "Student Number: " + studentNumber + "\n\n";
var recipients = studentNumber + "@email.com";
var subject = "Test Email";
MailApp.sendEmail(recipients, subject, message);
}
我希望能够从Google表单中收集学生电子邮件,该电子邮件已经保存在该表单所附电子表格的第3列中。
答案 0 :(得分:0)
很抱歉,我要离开时,我的回答有些仓促。 (就像我的代码一样。)通常不这样做,但是由于您是一位愿意例外的老师。
希望以下代码有帮助。 (这就是我要完成的任务。)
function helpingTheTeacher() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("YOUR_SHEET_NAME_HERE");
var values = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();
for (var i = 0; i < values.length; i++){
var timeStamp = values[i][0];
var studentName = values[i][1];
var studentNumber = values[i][2];
var studentGrade = values[i][3];
var message = "Hi " +studentName + " your grade is " +studentGrade + "."
var email = studentNumber + "@email.com";
var subject = "ALERT: MESSAGE FROM TEACHER!!!";
MailApp.sendEmail(email, subject, message)
}//END OF FOR LOOP
}//END OF FUNCTION