Google Apps Script - Delay sending an email by 48 hours -
i need delay sending email by 48 hours. i've tried:
var mail_date_plus_2 = new date(date.setdate(mail_date+2))
but error:
"referenceerror: "date" not defined. (line 26, file "code").
here script:
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 , time '+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 send mail @ '+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 @ '+cdate) } } } row++; } }
where date
is, need change mail_date
. firest make sure mail_date
date type. can check javascript variable types key word typeof
.
var mail_date = values[v][5]; logger.log('typeof mail_date: ' + typeof mail_date);
if mail_date
not date type, convert date:
var mail_date = values[v][5]; if (typeof mail_date !== 'object') {//in javascript date "object" type mail_date = new date(mail_date); }; var mail_date_plus_2 = new date(mail_date.setdate(mail_date+2))
Comments
Post a Comment