【问题标题】:Gmail script: Filters, stars and gmailApp.search, but some emails fall through the cracksGmail 脚本:过滤器、星标和 gmailApp.search,但有些电子邮件会漏掉
【发布时间】:2016-07-26 02:22:18
【问题描述】:

事实:

我有一个在收件箱中搜索未读电子邮件的脚本,所有未加星标的内容都会从收件箱中删除并应用标签。 有过滤器可以将某些电子邮件地址标记为已加星标。

目标:

将收件箱中的所有内容移动到不相关的文件夹中。 除了加星标的项目。 还有一种方法允许手动拖回收件箱并确保它们留在那里。

问题:

大多数电子邮件都会根据需要进行处理。 只有一些加星标的电子邮件仍在应用脚本,因此从收件箱中移出并标记为“newLabel”

感谢您的帮助。如果有更好的方法来完成同样的事情,我会换掉它。

/**
* Get the label, or create it if it doesn't exist
 */
function _getAssistLabel() {
  /**
   * If you'd like your label to say something different, modify it here
   */
  var assist_label_text = "newLabel";
 /** 
  *Get the label
  */
  var label = GmailApp.getUserLabelByName(assist_label_text);
 /**
  *if Label isn't found, create it
  */
  if (label == null) {
    var label = GmailApp.createLabel(assist_label_text);
  }

  return label;
}


/**
 * Search for starred, unread messages in the inbox 
 * apply a label 
 * then archive message (remove from inbox)
 */
function addAssistLabels() {
  var label = _getAssistLabel();

 /**
  * If a message is unread, and is in the inbox and is NOT starred...
  */
  var threads = GmailApp.search('is:unread in:inbox -label:Starred  -label:Sales');

 /**  ..then label the message and remove it from the inbox.
  * This will make the message show up in the "folder"
  */
  for (var i = 0; i < threads.length; i++) {
    label.addToThread(threads[i]);
      threads[i].moveToArchive();
  }
}






/**  
  * Force threads with starred emails and any with label "forBoss" to return to inbox
  */

function forceInbox() {
  var label = GmailApp.getUserLabelByName("newLabel"); 
  var threads = GmailApp.search('label: newLabel label:forBoss');

  for (var i = 0; i < threads.length; i++) {
   label.removeFromThread(threads[i]);
      threads[i].moveToInbox();
  }
}

我使用此链接作为其中的一部分:Gmail Script: search then move to inbox, remove label

【问题讨论】:

    标签: google-apps-script gmail


    【解决方案1】:

    您的第一个线程没有正确接收邮件。

    var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales');
    

    你表示

    我有一个独立的脚本,可以在收件箱中搜索未读电子邮件,任何未加星标的都是 从收件箱中删除并应用标签。

    GmailApp.search() 应该只使用 is:unread in:inbox 来满足您的需求。 此外,使用搜索查询参数label: 之前不应有破折号。

    查看文档以获取接受的搜索查询参数列表here

    【讨论】:

    • 感谢您的帮助 SwagBomb 破折号的意思是 NOT 。所以它是未读的,它在收件箱中,它没有加星标,也没有标记销售。
    • 所以这有时是有效的。我已经多次检查过这些参数,但一定是读错了。再次感谢@swagbomb
    • 如果文档不希望我在搜索中使用标签,您将如何处理?我想也许我可以运行不同的工作流程,但无法超越当前的工作流程。
    猜你喜欢
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多