gpt4 book ai didi

google-apps-script - 谷歌应用程序脚本和 GmailApp : get just new messages

转载 作者:行者123 更新时间:2023-12-03 12:16:30 25 4
gpt4 key购买 nike

我正在尝试实现一个简单的谷歌脚本来处理 Gmail 用户收到的每封邮件。
我找到了一个执行以下操作的示例:

var threads = GmailApp.getInboxThreads();
for (var i=0; i < threads.length; i++) {
var messages = threads[i].getMessages();

for (var j=0; j < messages.length; j++) {
if (!messages[j].isUnread()) {
continue;
}
//process message
}
}
也就是说:我遍历收件箱中的所有邮件并搜索未读邮件。这仅在 1800 条消息上非常慢。
理想情况下,我正在寻找一个触发器,一旦收到每条新消息,它就会被触发。
如果没有这样的东西,我会尝试利用我看到的这个:
GmailApp.getMessageById(id)

最佳答案

抱歉回复晚了,但我遇到了同样类型的问题,我最终使用了 GmailApp.search() ......希望这会有所帮助。

// find unread messages
var threads = GmailApp.search('is:unread');
....

警告

This call will fail when the size of all threads is too large for the system to handle. Where the thread size is unknown, and potentially very large, please use the 'paged' call, and specify ranges of the threads to retrieve in each call.



看看 GmailApp.search(query)
GmailApp.search(query, start, max)

关于google-apps-script - 谷歌应用程序脚本和 GmailApp : get just new messages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12923901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com