我运行脚本时没有遇到任何错误,但没有发送邮件。
下面是使用的代码块。
// Declaring variables
var ss = SpreadsheetApp.getActiveSpreadsheet(); // Get active spreadsheet
var schedule = ss.getSheetByName("Duties & Timelines"); // Get the schedule sheet
function sendReminderEmail() {
var currentDate = Utilities.formatDate(new Date(), ss.getSpreadsheetTimeZone(), "yyyy-MM-dd");
var data = schedule.getRange("A:J").getValues();
const due = schedule.getRange("A:J").getValues().filter(function (row) {
var cell = schedule.getRange("I2:I");
cell.setNumberFormat('yyyy-mm-dd');
return cell == currentDate;
}); // Filter to get row with reports that are due
due.forEach(function(item) {
// Set the email details
const recipientEmail = "[email protected]";
const subject = "Monthly Reminder";
const body = "This is your monthly reminder.";
// Send the email
MailApp.sendEmail({
to: recipientEmail,
subject: subject,
body: body
});
})
}
使用 Date().valueOf() 获取 0000 处的日期;
function sendReminderEmail() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Duties & Timelines");
var vs = schedule.getRange("A2:J"+ sh.getLastRow()).getValues();
const dt = new Date();
const dv = new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();//date at midnight
const due = vs.filter(row => {
let d = new Date(r[8]);
let date = new Date(d.getFullYear(),d.getMonth(),d.getDate()).valueOf();//date at midnight
return d == dv;
}).filter(e => e);
due.forEach(function(item) {
const recipientEmail = "[email protected]";
const subject = "Monthly Reminder";
const body = "This is your monthly reminder.";
MailApp.sendEmail({
to: recipientEmail,
subject: subject,
body: body
});
})
}