针对Gmail自动回复的Google脚本按主题过滤

时间:2017-06-27 18:06:39

标签: google-apps-script gmail

我已设置了自动回复功能,以便在下班后发送电子邮件的任何人都会收到回复。我希望能够排除具有特定主题或某个发件人的电子邮件,因为他们不需要回复。

这可能吗?或者我必须使用标签来实现这一目标吗?请参阅下面的我的脚本

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 个答案:

答案 0 :(得分:0)

没关系。我想到了。刚刚将线程搜索更新为:     var threads = GmailApp.search(&#39; subject:&#34; xxx&#34; is:inbox after:&#39; + timeFrom);

显然,将xxx替换为您正在寻找的任何主题。