【问题标题】:Google Script for Gmail to Delete Emails With *Only* the Specified Label用于 Gmail 的 Google 脚本可删除带有 *Only* 指定标签的电子邮件
【发布时间】:2016-11-03 15:06:39
【问题描述】:

我正在尝试找到一种方法来定位只有一个标签的电子邮件。我想删除具有特定标签且超过 2 周的邮件。但是,我希望脚本忽略除指定标签之外还有其他标签的任何电子邮件。

例如,标签为 'Subscriptions' 的电子邮件被删除,但标签为 'Subscriptions' AND 'Keep !'不会。

我目前拥有的版本将删除任何带有指定标签的电子邮件,而不管应用了任何其他标签。

我使用Fred Mouniguet 公开的Gmail Cleaning Robot script 作为我的基础。

这是我目前所拥有的:

function gmailCleaningRobot() {

var delayDays = 14; // will only impact emails more than 2 weeks old
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays); // what was the date at that time?

// Get all the threads labeled 'Subscriptions'
var label = GmailApp.getUserLabelByName("Subscriptions");
var threads = label.getThreads(0, 100);

// we archive all the threads if they're unread AND older than the limit we set in delayDays
for (var i = 0; i < threads.length; i++) {
if (threads[i].getLastMessageDate()<maxDate && threads[i].isUnread())
{
threads[i].moveToTrash();
}
}
}

任何帮助将不胜感激!

【问题讨论】:

    标签: javascript email google-apps-script gmail


    【解决方案1】:

    您可以通过在 if 语句中的线程实例上使用 getLabels 来解决此问题。

    尝试以下操作。

    if (threads[i].getLastMessageDate()<maxDate && threads[i].isUnread() 
        && threads.getLabels().length == 1)
    

    【讨论】:

      猜你喜欢
      • 2013-04-06
      • 2018-02-05
      • 1970-01-01
      • 2018-03-08
      • 2020-12-28
      • 2017-07-27
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多