【问题标题】:Looping on messages (not threads) of a specific Gmail label循环播放特定 Gmail 标签的邮件(不是线程)
【发布时间】:2018-03-22 02:04:49
【问题描述】:

我通过以下步骤将特定消息(而不是整个线程)添加到标签to_process

  1. 在 Gmail 设置中关闭 Conversation Mode

  2. 将标签to_process应用于特定消息

  3. 显示消息时,我可以确认只添加了特定的消息例如,同一线程中的另一条消息没有此标签。这很好。

现在我想循环播放来自 Google Apps 脚本的所有这些消息。但问题是 API 只能授予对附加到某个标签的 threads 的访问权限:

var threads = GmailApp.search('label:to_process'); 
for (var i = 0; i < threads.length; i++) {
    // problem: here I cannot access to messages but only threads
}

var label = GmailApp.getUserLabelByName("to_process");
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
    // problem: here I cannot access to messages but only threads       
}

如何循环播放与标签关联的消息(而不是线程)?


开始解决方案,但我不知道如何继续:

var threads = GmailApp.search('label:to_process'); 
for (var i = 0; i < threads.length; i++) {
    var messages = threads[i].getMessages();
    for (var j = 0; j < messages.length; j++) {
        var message = messages[j];

        // pseudo code here because getMessageLabels doesn't exist
        //if ("to_process" is in message.getMessageLabels()) {
        //}

    }
}

【问题讨论】:

    标签: javascript google-apps-script gmail gmail-api


    【解决方案1】:

    我愿意 Advanced Gmail ServiceGmail API list(),然后是 getMessageById()

    function listMessages () {
      // Only return messages matching the specified query.
      var msgs = Gmail.Users.Messages.list('me', {'q':'label:to_process larger:5M'}).messages;
    
      // For each message - retrieve it by its id
      msgs.forEach(function (e){
        Logger.log("This email's subject is: %s", GmailApp.getMessageById(e.id).getSubject());
      });
    
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 2013-04-15
      • 2011-04-08
      • 1970-01-01
      • 2015-08-25
      • 2016-02-29
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多