We are trying to get e-mail notifications in cases there would be some dramatic changes in our revenue data. Could anyone please indicate possible errors why it wouldn't send e-mail?
function sendEmail() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet1");
const data = sh.getRange("B2:L80" sh.getLastRow()).getValues();
data.forEach(r=>{
let overdueValue = r[9];
if (overdueValue === "TRUE"){
let name = r[10];
let message = "Reach out to " name;
let subject = "Reach out to this person.";
//MailApp.sendEmail("[email protected]", subject, message);
GmailApp.sendEmail("[email protected]", subject, message);
}
});
}
CodePudding user response:
Try changing if (overdueValue === "TRUE")
to if (overdueValue === true)
Updated Code:
function sendEmail() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet1");
const data = sh.getRange("B2:L80" sh.getLastRow()).getValues();
data.forEach(r=>{
let overdueValue = r[9];
if (overdueValue === true){
let name = r[10];
let message = "Reach out to " name;
let subject = "Reach out to this person.";
//MailApp.sendEmail("[email protected]", subject, message);
GmailApp.sendEmail("[email protected]", subject, message);
}
});
}
Notes: