Вопрос
Почему мой sendEmail не работает?
Ответ
Ваш синтаксис sendEmail неверный, вам не хватает subject
- Проверьте правильный синтаксис для sendEmail ()
function sendEmail(){
MailApp.sendEmail(recipient, subject, body)
}
Пример:
function sendEmail(){
MailApp.sendEmail("user4172070@gmail.com", "testing sendEmail via Apps Script", "It's working")
}
Адаптация к вашему коду
MailApp.sendEmail(emails, "Email Subject", msg);
Окончательная версия
function myfunction() {
var sheet = SpreadsheetApp.getActiveSheet();
// figure out what the last row is
var lastRow1 = sheet.getLastRow();
// the rows are indexed starting at 1, and the first row
// is the headers, so start with row 5
var startRow1 = 5;
// grab column 6 (the 'days left' column)
var range = sheet.getRange(5, 6, lastRow1 - startRow1 + 1, 1 );
var numRows = range.getNumRows();
var days_left_values = range.getValues();
// Now, grab the reminder name column
range = sheet.getRange(5, 3, lastRow1 - startRow1 + 1, 1);
var reminder_info_values = range.getValues();
range = sheet.getRange(5, 7, lastRow1 - startRow1 + 1, 1);
var emails_info_values = range.getValues();
var warning_count = 0;
var msg = "";
// Loop over the days left values
for (var i = 0; i <= numRows - 1; i++) {
var days_left = days_left_values[i][0];
if(days_left == 1) {
// if it's exactly 1, do something with the data.
var reminder_name = reminder_info_values[i][0];
msg = msg + "Reminder: " + reminder_name + " is due in " + days_left + " days.\n";
warning_count++;
}
var emails = emails_info_values [i][0];
if(warning_count) {
MailApp.sendEmail(emails, "Email Subject", msg);
}
}
}
Ссылка: