我添加了具体的messages(而且不是全部thread) 到标签to_process
通过以下步骤:
Turn Conversation Mode
Gmail 设置中关闭
贴上标签to_process
到特定消息
当显示消息时,我可以确认只有特定的messages已添加。例如,同一线程中的另一条消息没有此标签。这很好。
现在我想循环处理来自 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
}
or
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()) {
//}
}
}
我会和高级 Gmail 服务 https://developers.google.com/apps-script/advanced/gmail和Gmail API 列表() https://developers.google.com/gmail/api/v1/reference/users/messages/list, then getMessageById() https://developers.google.com/apps-script/reference/gmail/gmail-app#getMessageById(String) :
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());
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)