我正在尝试发送一封仅包含新行数据的电子邮件。我将第21列设置为在发送电子邮件时添加已发送,并且脚本将忽略该消息(如果该消息在该单元格中显示为已发送)。问题是它将所有行数据发送到我的电子邮件地址。
function onEdit() {
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,1000);
var AllValues = WholeRange.getValues();
var message = "";
for (i in AllValues) {
var CurrentRow = AllValues[i];
//Sent?
var EmailSent = CurrentRow[21];
//if row has been sent
if (EmailSent == "sent")
continue;
message +=
"<p><b>New RMA?: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Device SKU: </b>" + CurrentRow[5] + "</p>" +
"<p><b>ESN / MEID: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Reason for RMA: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Defective Out of Box?: </b>" + CurrentRow[10] + "</p>" +
"<p><b>Date Sold: </b>" + CurrentRow[11] + "</p>" +
"<p><b>Vendor: </b>" + CurrentRow[12] + "</p>" +
"<p><b>Email Address: </b>" + CurrentRow[13] + "</p><br><br>";
var setRow = parseInt(i) + StartRow;
ActiveSheet.getRange(setRow, 21).setValue("sent");
}
var SendTo = "davidm@email.com";
var Subject = "RMA Submission";
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}
如何使用上述脚本解决此问题?
我尝试了这个但没有成功。它包括所有136行,而不仅仅是第22列中没有SENT的新行
function onEdit() {
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,22); //<---Changed
var AllValues = WholeRange.getValues();
var message = "";
for (i in AllValues) {
var CurrentRow = AllValues[i];
var EmailSent = CurrentRow[22];
if (EmailSent == "sent")
continue;
message +=
"<p><b>New RMA?: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Device SKU: </b>" + CurrentRow[5] + "</p>" +
"<p><b>ESN / MEID: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Reason for RMA: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Defective Out of Box?: </b>" + CurrentRow[10] + "</p>" +
"<p><b>Date Sold: </b>" + CurrentRow[11] + "</p>" +
"<p><b>Vendor: </b>" + CurrentRow[12] + "</p>" +
"<p><b>Email Address: </b>" + CurrentRow[13] + "</p><br><br>";
var setRow = parseInt(i) + StartRow;
ActiveSheet.getRange(setRow, 22).setValue("sent");
}
var SendTo = "davidm@";
var Subject = "RMA From" +" "+ CurrentRow[13]; //<---Changed
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}
function SendEmail() {
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,20);
var AllValues = WholeRange.getValues();
var message = "";
for (i in AllValues) {
var CurrentRow = AllValues[i];
var EmailSent = CurrentRow[18];
Logger.log(CurrentRow[18]);
if (EmailSent == "Sent")
continue;
message =
"<p><b>Email?: </b>" + CurrentRow[1] + "</p>" +
"<p><b>District: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Vendor Cost: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Vendor Cost: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Default Price: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Vendor: </b>" + CurrentRow[6] + "</p>" +
"<p><b>Vendor SKU: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Manufacturer: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Manufacturer SKU: </b>" + CurrentRow[9] + "</p>" +
"<p><b>Barcode: </b>" + CurrentRow[10] + "</p>"+
"<p><b>Category: </b>" + CurrentRow[11] + "</p>" +
"<p><b>Device: </b>" + CurrentRow[12] + "</p>" +
"<p><b>Model: </b>" + CurrentRow[13] + "</p>"+
"<p><b>Color: </b>" + CurrentRow[18] + "</p>";
var setRow = parseInt(i) + StartRow;
ActiveSheet.getRange(setRow, 19).setValue("Sent");
}
var SendTo = "";
//var SendToEmail = "";
var Subject = "New Sku:" +" "+ CurrentRow[13] +" " +"From:"+" "+CurrentRow[1];
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
// MailApp.sendEmail({
// to: SendToEmail,
// cc: "",
// subject: Subject,
// htmlBody: message,
// });
}