Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9842

Can anyone suggest how to also include work hours (9-5) in this out-of-office script?

$
0
0

The below script successfully auto-replies to sender on selected non-working-days.Can anyone suggest how I might add the after-hours of working-days, say 5pm-7am, to trigger the reply also?

function autoReply() {  var interval = 5;        //  if the script runs every 5 minutes; change otherwise  var daysOff = [1,5,6,0];   // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su  var date = new Date();  var day = date.getDay();  var label = GmailApp.getUserLabelByName("autoresponded");  if (daysOff.indexOf(day) > -1) {    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;    var threads = GmailApp.search('is:inbox !label:autoresponded after:'+ timeFrom);    for (var i = 0; i < threads.length; i++) {      var message = threads[i].getMessages()[0];      if (message.getFrom().indexOf("myemail@gmail.com") < 0 && message.getFrom().indexOf("no-repl") < 0 && message.getFrom().indexOf("bounce") < 0 && message.getFrom().indexOf("spam") < 0) {        threads[i].reply("", {          htmlBody: "<p>Thank you for your message. I am not in the office today. If you have urgent questions you can email office@example.com. If you have other urgent enquiries you can call the office on 1800 999 002.</p><p>Best regards,<br>Name</p>"        });        label.addToThread(threads[i]);      }    }  }}

Viewing all articles
Browse latest Browse all 9842

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>