Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在谷歌应用程序脚本中省略自动回复指定电子邮件_Javascript_Google Apps Script_Gmail - Fatal编程技术网

Javascript 如何在谷歌应用程序脚本中省略自动回复指定电子邮件

Javascript 如何在谷歌应用程序脚本中省略自动回复指定电子邮件,javascript,google-apps-script,gmail,Javascript,Google Apps Script,Gmail,我正在尝试添加一个逻辑,允许我跳过保留在数组中的电子邮件列表,以避免在我的谷歌应用程序脚本中自动回复。我相信问题在于最后的if语句的条件语句,但无法解决它。如果我向收件箱发送3封电子邮件,其中2封来自省略列表上的地址,并运行脚本几次,它只会发送到它应该发送的邮件,并且工作正常。一旦另一封邮件出现在第四封邮件中,而该邮件也不在省略列表中,它就会回复该邮件以及省略列表中的另外两封邮件。非常感谢您的帮助,谢谢 function autoReply() { var interval = 5;

我正在尝试添加一个逻辑,允许我跳过保留在数组中的电子邮件列表,以避免在我的谷歌应用程序脚本中自动回复。我相信问题在于最后的if语句的条件语句,但无法解决它。如果我向收件箱发送3封电子邮件,其中2封来自省略列表上的地址,并运行脚本几次,它只会发送到它应该发送的邮件,并且工作正常。一旦另一封邮件出现在第四封邮件中,而该邮件也不在省略列表中,它就会回复该邮件以及省略列表中的另外两封邮件。非常感谢您的帮助,谢谢

  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();
  var noReply = ["ls@compass.com", "feedback@compass.com", "jenkins@compass.com", "shamirwehbe@me.com", "shamirwehbe@yahoo.com"];
  var fromEmails = [];
  var yesReply

  var replyMessage = "Hello!\n\nYou have reached me during non business hours. I will respond by 9 AM next business day.\n\nIf you have any Compass.com related questions, check out Compass Academy! Learn about Compass' tools and get your questions answered at academy.compass.com.\n\nBest,\n\nShamir Wehbe";

  if ([6,0].indexOf(day) > -1 || (hour < 9) || (hour >= 17)) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;  
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    var label = GmailApp.getUserLabelByName("autoReplied");

    for (var i = 0; i < threads.length; i++) {

      var messagesFrom = threads[i].getMessages()[0].getFrom();
      var email = messagesFrom.substring(messagesFrom.lastIndexOf("<") + 1, messagesFrom.lastIndexOf(">"));
      fromEmails.push(email);

      yesReply = fromEmails.filter(function(e) {
        return noReply.indexOf(e) ==-1;});


        for (var y = 0; y < fromEmails.length; y++) {

         if (threads[i].isUnread() && yesReply.indexOf(fromEmails[y]) > -1){

            threads[i].reply(replyMessage);
            threads[i].markRead();
            threads[i].addLabel(label);

        }
      }               
    }    
  } 
}
函数自动回复(){
var interval=5;//如果脚本每5分钟运行一次,则更改为其他
变量日期=新日期();
var day=date.getDay();
var hour=date.getHours();
var noReply=[”ls@compass.com", "feedback@compass.com", "jenkins@compass.com", "shamirwehbe@me.com", "shamirwehbe@yahoo.com"];
var fromEmails=[];
var yesReply
var replyMessage=“您好!\n\n您在非营业时间与我取得联系。我将在下一个营业日上午9点之前回复。\n\n如果您有任何与Compass.com相关的问题,请访问Compass Academy!了解Compass的工具,并在Academy.Compass.com上获得您的问题的答案。\n\n贝斯特,\n\n哈米尔·韦赫贝”;
如果([6,0].indexOf(日)>-1 | | |(小时<9)| | |(小时>=17)){
var timeFrom=Math.floor(date.valueOf()/1000)-60*间隔;
var threads=GmailApp.search('is:inbox after:'+timeFrom);
var label=GmailApp.getUserLabelByName(“自动回复”);
对于(var i=0;i-1){
线程[i]。回复(replyMessage);
线程[i].markRead();
线程[i]。添加标签(标签);
}
}               
}    
} 
}
我认为您的做法不正确,但如果我弄错了,请纠正我。我看到的问题是,您正在线程中循环,并在同一个循环中发送回复。这是一个奇怪的结构,我想你可以简化它

不要构建一个
yesReply
数组,只需检查电子邮件地址是否在
noReply
数组中,并相应地回复即可

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();
  var noReply = ["ls@compass.com", "feedback@compass.com", "jenkins@compass.com", "shamirwehbe@me.com", "shamirwehbe@yahoo.com"];
  var replyMessage = "Hello!\n\nYou have reached me during non business hours. I will respond by 9 AM next business day.\n\nIf you have any Compass.com related questions, check out Compass Academy! Learn about Compass' tools and get your questions answered at academy.compass.com.\n\nBest,\n\nShamir Wehbe";

  if ([6,0].indexOf(day) > -1 || (hour < 9) || (hour >= 17)) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;  
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    var label = GmailApp.getUserLabelByName("autoReplied");

    for (var i = 0; i < threads.length; i++) {
      var thread = threads[i];
      var messagesFrom = thread.getMessages()[0].getFrom();
      var email = messagesFrom.substring(messagesFrom.lastIndexOf("<") + 1, messagesFrom.lastIndexOf(">"));

      if (thread.isUnread() && noReply.indexOf(email) == -1) {
        thread.reply(replyMessage);
        thread.markRead();
        thread.addLabel(label);
      }              
    }    
  } 
}
函数自动回复(){
var interval=5;//如果脚本每5分钟运行一次,则更改为其他
变量日期=新日期();
var day=date.getDay();
var hour=date.getHours();
var noReply=[”ls@compass.com", "feedback@compass.com", "jenkins@compass.com", "shamirwehbe@me.com", "shamirwehbe@yahoo.com"];
var replyMessage=“您好!\n\n您在非营业时间与我取得联系。我将在下一个营业日上午9点之前回复。\n\n如果您有任何与Compass.com相关的问题,请访问Compass Academy!了解Compass的工具,并在Academy.Compass.com上获得您的问题的答案。\n\n贝斯特,\n\n哈米尔·韦赫贝”;
如果([6,0].indexOf(日)>-1 | | |(小时<9)| | |(小时>=17)){
var timeFrom=Math.floor(date.valueOf()/1000)-60*间隔;
var threads=GmailApp.search('is:inbox after:'+timeFrom);
var label=GmailApp.getUserLabelByName(“自动回复”);
对于(var i=0;i
嗯,我完全把这件事复杂化了。它现在工作得很好。非常感谢你!!