2
votes

I have set up an auto reply so that anyone who emails after hours will receive a response. What I'm hoping to do is be able to exclude emails that have a certain subject or a certain sender since they don't need the reply.

Is this possible? Or do I have to use labels to achieve this? See my script below.

function autoReply() {
var interval = 5;  
  var date = new Date();
  var day = date.getDay();
  var hour = date.getHours();
  if ([6,0].indexOf(day) > -1 || (day == 1 && hour < 6) || (day == 1 && hour >= 19) || (day == 2 && hour < 6) || (day == 2 && hour >= 19) ||(day == 3 && hour < 6) || (day == 3 && hour >= 19) ||(day == 4 && hour < 6) || (day == 4 && hour >= 19) ||(day == 5 && hour < 6) || (day == 5 && hour >= 19)) {
   var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
   var threads = GmailApp.search('is:inbox after:' + timeFrom);
   for (var i = 0; i < threads.length; i++) {
      if (threads[i].isUnread()){
      threads[i].reply("Thank you for your email. We are currently outside our regular office hours of 6am to 7pm Pacific Time, Monday through Friday. We will respond to you once we are back in the office. \n\nIf you have already signed up for flight monitoring and need urgent assistance during those travels, please contact your assigned concierge directly and he or she will be able to help.");
      threads[i].markRead();
      threads[i].markImportant();
      }
    }
  }
}
1

1 Answers

0
votes

Nevermind. I figured it out. Just updated the threads search to: var threads = GmailApp.search('subject:"xxx" is:inbox after:' + timeFrom);

Obviously replace the xxx with whatever subject you're looking for.