Reputation: 172
I want the function that will make my script ignore send merge emails to the previous emails that I collected using Google Form when someone new submits his information.
Here is the script I'm using:
function sendMail() {
const emailTemp = HtmlService.createTemplateFromFile("email");
const sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("form1");
const startRow = 2
const data = sh.getRange(startRow, 2, sh.getLastRow() - 1, sh.getLastColumn() - 1).getValues();
data.forEach((row, i) => {
emailTemp.fullname = row[1];
emailTemp.phone = row[2];
let htmlMessage = emailTemp.evaluate().getContent();
let emailSent = row[6];
if (emailSent != "EMAIL_SENT") {
GmailApp.sendEmail(row[0],"Thank you!","Your email doesn't support HTML.",{ name: "Email App", htmlBody: htmlMessage });
sh.getRange(startRow + i, 6).setValue("EMAIL_SENT");
}
});
}
I want to ignore all the Rows that have EMAIL_SENT value in the Column F :
Thank you.
Upvotes: 2
Views: 38
Reputation: 64082
That's what this line is for if (emailSent != "EMAIL_SENT") {
This let emailSent = row[6];
should be this let emailSent = row[4];
Your row starts at column 2 according to your original question.
Upvotes: 2