我正在运行一个脚本,该脚本应该向输入到特定工作表单元格中的电子邮件发送消息。我收到错误无法发送电子邮件:没有收件人
function emai() {
var EMAIL_SENT = 'EMAIL_SENT';
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet5')
var startRow = 2; // First row of data to process
var numRows = 1000; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 2, numRows, 1000);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[1]; // First column
var message = "b"
var emailSent = row[26]; // Third column
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = 'Sending emails from a Spreadsheet';
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 1000).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
答案 0 :(得分:0)
尝试一下:
function email() {
var EMAIL_SENT='EMAIL_SENT';
var sheet=SpreadsheetApp.getActive().getSheetByName('Sheet5')
var startRow=2;
var numRows=1000;
var dataRange=sheet.getRange(startRow, 2, numRows, sheet.getLastColumn()-1);
var data=dataRange.getValues();
for (var i=0;i<data.length; i++) {
var row=data[i];
var emailAddress = row[1]; // Column 2
var message = "b"
var emailSent = row[26]; // Column 28
if (emailSent != EMAIL_SENT) {
var subject = 'Sending emails from a Spreadsheet';
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(i + startRow - 1, 28).setValue(EMAIL_SENT);
}
}
}
如果这不起作用,我们将需要查看您的电子表格的副本,因为您的许多注释没有任何意义。