在作業完成時對作業發送電子郵件。我添加了一個我認爲會阻止兩次電子郵件的部分。無法找出原因。從Google文檔電子表格發送電子郵件
function sendEmail()
{
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var numRows = sheet.getLastRow();
var EMAIL_SENT = "EMAIL_SENT";
var dataRange = sheet.getRange(startRow, 1, numRows, 3)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i)
{
var row = data[i];
var emailAddress = row[1];
var message = "Correction Completed for " + row[2];
var subject = "Correction Completed";
var emailSent = row[9];
if (emailSent != "EMAIL_SENT") //prevent sending duplicate messages
{
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 9).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
我的想法是把sendEmail部分放在一個if語句中,它不會發送。不過,它仍然會發送一封電子郵件。先謝謝你。
是的。這對我有效。謝謝! – user2122765 2013-03-01 15:52:54