I wrote a code to send mails automatically from google sheet. Every day if column Status has the cell "Timing" I want to send email. And it works. But I don't want to send mails to the people that received mail in previous days, so that I created CHECK to fill the another column by 'sent' after sending an email. It failed. I can't detect the row with an emailaddress that program used to go relatively to another column to insert "sent".
Could you help me?
function sendEmails() {
var she = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("basic");
var startRow = 2;
var numRows = 1000;
var dataRange = she.getRange(startRow, 1, numRows, 1000)
var data = dataRange.getValues();
var text = she.getRange("L2");
var message = text.getValues();
for (i in data) {
var col = data[i];
var emailAddress = col[1];
var subject = "Project reminder";
var status = col[3];
var check = col[8];
if (status == "Timing"){
MailApp.sendEmail(emailAddress, subject, message) &&
check.setValue('sent');} //moment when I want to insert 'sent'
}
}
Updated part of the code:
for(var a=0; a < values.length; a++ ){
if(values[a][1] == "not" && values[a][3] == "Timing"){
var emailAddress = values[a][0];
Logger.log("NEED TO SEND AN EMAIL TO " + values[a][0]);
var message = messag + " " + values[a][5];
MailApp.sendEmail(emailAddress, subject, message);
}
}
}