So, I've been working on a project and that involves a code that sends emails automatically. The code is supposed to write "Email Sent" on the far-right column, besides each balance.
So, here's my auto-email function and a link to the spreadsheet: https://docs.google.com/spreadsheets/d/14ukVvpMh0dJr5_HLUYxK1n4m6HXd2tvAj-bMrixAQFg/edit?usp=sharing
function sendEmails() {
var EMAIL_SENT = "EMAIL SENT"
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Control_Mens")
var dataRange = sheet.getRange(2, 2, 61, 16)
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0];
var message = row[1];
var emailSent = row[15]
if (emailSent != EMAIL_SENT){
var subject = "Subject";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(2 + i, 17).setValue(EMAIL_SENT);
}
}
}
While I think I may be counting something wrong (like one more row and vice-versa), I've ran it multiple times, it sends the email to everyone in the sheet, but it only writes "EMAIL SENT" beside specific people.