Google Email自动回复Email-可用于Google Voice短信自动回复

(update 2020_05_11)修改了避免死循环。

总体思路是 –

  • Filter & Label: 根据过滤器(Filter)给特定 Email 加上标签(Label)
  • AutoReply on label: 开启自动检查标签并回复相关所有 Email

Filter & Label

这个比较容易 – 比如建立针对所有发件人为 (@txt.voice.google.com)的 Filter, 加上 Label “autoReply”

配合这篇每月自动给 Google Voice 发消息的IFTTT (本馆档案), 然后自动回复, 完美保号.

一定不能将”标记为已读”打勾

自动回复 Email

  • 3- 输入下面的代码

核心逻辑就是连续回复3次,不然等12小时后再回;但如果消息中带有 “NoReply” (不区分大小写)的话,那就不回复。

function autoReplier() {
  var labelObj = GmailApp.getUserLabelByName('autoReply');
  var gmailThreads;
  var messages;
  var messagecount;
  var sender;
  var num = 3;  //设置连续自动回复邮件的次数(为防止两人都是自动回复,当发送次数超过时将不自动回复)。
  var hours = 12;  //过了多少小时后又可以自动回复。
    
  for (var gg = 0; gg < labelObj.getUnreadCount(); gg++) {
    gmailThreads = labelObj.getThreads()[gg];
    // process only if the thread has unread msg
    if (gmailThreads.isUnread()) {
      messages = gmailThreads.getMessages();
      messagecount = gmailThreads.getMessageCount();
      //console.log(messages[messagecount - 9].getDate() + "  time");
      console.log("unread thread with " + messagecount + " total messages in the past.");
      for (var ii = 0; ii < messages.length; ii++) {
        if (messages[ii].isUnread()) {
          msg = messages[ii].getPlainBody();
          sender = messages[ii].getFrom(); 
          
          array = [["最灵繁的人也看不见自己的背脊。-非洲NoReply"],
                   ["最困难的事情就是认识自己。-希腊NoReply"],
                   ["有勇气承担命运这才是英雄好汉。-黑塞NoReply"],
                   ["Well Received, thanks! -NoReply"],
                   ["最大的挑战和突破在于用人,而用人最大的突破在于信任人。—马云NoReply"]];
          
          var j = Math.floor(Math.random() * (array.length));
          var temp = array[j];
          
          // skip any messages including "noreply"
          if (!msg.toLowerCase().includes("noreply")) {
            if (messagecount < num){
              console.log("messagecount < num, 1 normal msg sent.");
              MailApp.sendEmail(sender, "Auto Reply", temp);
            } else if (messagecount == num) {
              console.log("Limit hit, 1 last msg sent.");
              MailApp.sendEmail(sender, "Auto Reply", "Limit hit - last msg in reply.");
            } else if((messages[messagecount - 1].getDate().getTime() 
                       - messages[messagecount - num].getDate().getTime()) 
                       > hours * 60 * 60 * 1000 ){
                console.log("Resume to reply message after a grace period.");
                MailApp.sendEmail(sender, 
                                  "Auto Reply", 
                                  "Hi, there!Let's take a break!Google Apps Script NoReply");
              }
          }
          messages[ii].markRead();
          //messages[ii].moveToTrash(); // delete email
        }
      }
    }
  }
}
  • 4- 新建 “触发器” – 看右边
  • 5- 修改为”分钟定时器” – 其他不用变
  • 6- 允许未验证的应用

这就ok 了. 效果看封面图片.

1 thought on “Google Email自动回复Email-可用于Google Voice短信自动回复”

  1. Pingback: 拿到一个新的Google Voice号码之后该做… – 1024 & 4201

Leave a Reply