我在google脚本上写了我的第一个代码,试图在截止日期之前/之后/之后发送自动电子邮件。尽管前两个条件都可行,但是当截止日期是将来的日期时,我没有设法发送电子邮件。
考虑以下代码:
function EmailReminder() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A2:C4");
var UserData = range.getValues();
var today = Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy");
for (i in UserData){
var row = UserData[i];
var Contact = row[0];
var ActionNeeded = row[1];
var ActionDeadline = row[2];
var ActionDeadlines = Utilities.formatDate(new Date(ActionDeadline),"GMT+1","dd/MM/yyyy");
if (ActionDeadlines < today) {
MailApp.sendEmail(row[0], "Action pending for your project ","Dear PM,\n\nFor your project, the deadline to complete the following action was on " + ActionDeadline + ": \n\n*****\n\n" + ActionNeeded + "\n\n*****\n\nKindly take appropriate action as soon as possible.");
}
else if (ActionDeadlines == today) {
MailApp.sendEmail(row[0], "Action pending for your project ","Dear PM,\n\nFor your project, the deadline to complete the following action is today: \n\n*****\n\n" + ActionNeeded + "\n\n*****\n\nKindly take appropriate action as soon as possible.");
}
else if (ActionDeadlines > today) {
MailApp.sendEmail(row[0], "Action pending for your project ","Dear PM,\n\nFor your project, there is an upcoming deadline due on the " + ActionDeadline + ": \n\n*****\n\n" + ActionNeeded + "\n\n*****\n\nKindly take appropriate action as soon as possible.");
}
}
}
样本数据:
Contact ActionNeeded Deadline
Insert email function for a past deadline =today()-5
Insert email function for a current deadline =today()
Insert email function for a future deadline =today()+5
结果:
如何将其保留为dd / MM / yyyy?