我正在使用我在这里看到的代码中的函数: http://mashe.hawksey.info/2012/09/google-app-script-scheduling-timed-triggers/ 我按照指示添加了子功能。
function scheduledCollection2(){
var schedule = [];
// dates/times in mm/dd/yyyy hh:mm - timezone matches settings in File > Project properties
schedule.push({start:"10/25/2014 09:00", end:"12/25/2014 10:00"});
checkCollect2(schedule);
}
function checkCollect2(schedule){
var now = new Date();
for (i in schedule){
var start = new Date(schedule[i].start);
var end = new Date(schedule[i].end);
if (now > start && now < end){
function sendEmails() {
var emailAddress = "abc@gmail.com";
var message = "Hello, this is a test email.";
var subject = "Sending Recurring Emails";
MailApp.sendEmail(emailAddress, subject, message);
}
}
}
}
sendEmails功能单独运行良好。但是,当我因某种原因将其添加到代码的其余部分时,它会停止工作。我的目标是让它与时间驱动的触发器一起工作。
有关它为什么不起作用以及如何让它工作的任何建议?
答案 0 :(得分:0)
简单地以不同的方式构建脚本:(而不是定义函数只执行代码)
function checkCollect2(schedule){
var now = new Date();
for (i in schedule){
var start = new Date(schedule[i].start);
var end = new Date(schedule[i].end);
if (now > start && now < end){
var emailAddress = "abc@gmail.com";
var message = "Hello, this is a test email.";
var subject = "Sending Recurring Emails";
MailApp.sendEmail(emailAddress, subject, message);
}
}
}