我使用以下步骤将特定的消息(而不是整个线程)添加到标签to_process
:
在Gmail设置中关闭Conversation Mode
将标签to_process
应用于特定邮件
显示消息时,我可以确认只添加了特定的消息。 例如,同一个帖子中的另一条消息没有此标签。这很好。
现在,我想从Google Apps脚本中循环播放所有这些消息。但问题是API只能访问附加到某个标签的线程:
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()) {
//}
}
}
答案 0 :(得分:0)
我会去 Advanced Gmail Service和Gmail 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());
});
}