Попробуйте следующим образом:
function sendEmails() {
var sheet=SpreadsheetApp.getActiveSheet();
var startRow=2;
var dataRange=sheet.getRange(startRow,1,sheet.getLastRow()-startRow+1,sheet.getLastColumn());//I think startRow is a better fit for the first parameter and my guess is that you did't really intend for data.length to be only 1 row.
var data=dataRange.getValues();
for (var i=0;i<data.length;++i) {
var row=data[i];
var emailAddress=row[5];//column 6
var message=Utilities.formatString('Hello,\n\nWe have received an inquiry from your customer in Inbound.\n\nLead No is - %s\n\nKindly arrange a callback.\n\nRegards,\nTeam Inbound\n\nThis is an auto-generated email.',row[1]);
var emailSent = row[7];//column 8
if (emailSent != "EMAIL_SENT") { // Prevents sending duplicates
var subject = "Inbound Inquiry"+ " - " + row[1];//column 2
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 8).setValue("EMAIL_SENT");//column 8 and I don't think it's necessary to flush in the loop
}
}
}
Проверьте комментарии, чтобы убедиться, что я получил правильные столбцы.
Считайте Sheet.getRange (строка, столбец, количество строк), количество столбцов)