计划自动回复来自域的电子邮件

时间:2016-05-13 11:34:27

标签: google-apps-script

我使用下面的脚本来安排不在办公室的回复,但希望它只适用于从特定域收到的电子邮件。

有人可以帮助我调整这个脚本吗?

function autoReply() {
  var interval = 5;    //  if the script runs every 5 minutes; change otherwise
  var date = new Date();
  var day = date.getDay();
  var hour = date.getHours();
  if ([5,6].indexOf(day) > -1 || (day == 0 && hour < 7) || (day == 4 && hour >= 16)) {
    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++) {
      threads[i].reply("Out of office hours. Your email will not read until Sunday morning.");
    }
  }
}

1 个答案:

答案 0 :(得分:0)

You can tweak the Gmail search query to include the from: search operator. As the is:inbox should be in:inbox.

var threads = GmailApp.search('in:inbox from:example.com after:' + timeFrom);

If you run the script via trigger, there's a possibility that the same emails is replied multiple times. Therefore you can consider using thread.moveToArchive() to remove the message from inbox after it has been responded.