I’m running some Google Apps Script that intereracts with a Google Sheet that extracts and compares some values as the sheet is updated and sends an email if certain criteria are exceeded. It has worked solidly for over a year but recently stopped and I’ve found the problem to be with the new Chrome V8 runtime environment. If I run the legacy java environment – it works, no problem.
The script looks for a condition whereby a threshold, set in the spreadsheet is exceeded – if so it should send an email. I have proven that the script identifies the threshold exceeded condition, that it can write and read values from the spreadsheet and that it can read and write the email address from a cell.
It seems that the MailApp.sendEmail(emailAddress, subject, message);
doesn't work. Any suggestions greatly appreciated.
Script extract is as follows:
var DP_THRESH1 = doc.getSheetByName("DASHBOARD").getRange("L11"); //THRESHOLD
var DP_THESHOLD1 = DP_THRESH1.getValue();
var DP_SPREAD1 = doc.getSheetByName("DASHBOARD").getRange("H11"); //CALCULATED SPREAD
var DP_LASTSPREAD1 = DP_SPREAD1.getValue();
if (DP_LASTSPREAD1 < DP_THESHOLD1){
// SET TO ZERO IS READY TO EMAIL STATE - THRESHOLD NOT EXCEEDED
doc.getSheetByName("mailSheet").getRange('N2').setValue('0');
}
//EMAIL STATUS = 0 = READY TO EMAIL - 1 = HAVE SENT EMAIL
var EMAIL_status = doc.getSheetByName("mailSheet").getRange("N2");
var EMAIL_oneshot = EMAIL_status.getValue();
if ((DP_LASTSPREAD1 > DP_THESHOLD1) && (EMAIL_oneshot == 0)) {
// IF THRESHOLD EXCEEDED AND NO EMAIL SENT
doc.getSheetByName("mailSheet").getRange('N2').setValue('1');
// Fetch the email address
var emailRange = doc.getSheetByName("mailSheet").getRange("B2");
var emailAddress = emailRange.getValues();
// Send Alert Email.
var message = 'measured value is ' + DP_LASTSPREAD1;
var subject = 'Possible Choke Alert';
MailApp.sendEmail(emailAddress, subject, message);
}