0
我需要延遲48小時發送電子郵件。我已經試過:Google Apps腳本 - 延遲48小時發送電子郵件
var mail_date_plus_2 = new Date(date.setDate(mail_date+2))
,但我得到的錯誤:
"ReferenceError: "date" is not defined. (line 26, file "Code").
下面是腳本:
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data_sheet = ss.getSheetByName('Sheet1');
var values = data_sheet.getRange(2, 1, data_sheet.getLastRow(), data_sheet.getLastColumn()).getValues();
var row = 2;
var current_time= new Date();
Logger.log('Current data and time is '+current_time)
for(var v in values) {
var mail_note = data_sheet.getRange(row, 1).getNote();
if(mail_note=='') {
var mail_date = values[v][5];
if(mail_date!='') {
if(current_time>mail_date) {
Logger.log(v+'>>Need to send mail at '+mail_date);
var name = values[v][2];
var email = values[v][4];
var form = values[v][1];
var htmlbody = RESERVATION_EMAIL_HTML;
var prefix = 'Dear '+name+', '+"<br/><br/>";
htmlbody = prefix + htmlbody
if(form=='Reservation') {MailApp.sendEmail({
to: email,
subject: EMAIL_SUBJECT,
htmlBody: htmlbody,
});
}
var cdate = new Date();
data_sheet.getRange(row, 1).setNote('Mail has been sent at '+cdate)
}
}
}
row++;
}
}
謝謝大家的響應。更改後,我收到另一個錯誤: TypeError:在對象中找不到函數setDate。 (第28行,文件「代碼」) –
查看更新的答案。 –