Gmail 脚本:存档来自不在我的联系人列表中且超过 2 天的人的电子邮件
Gmail script: Archive emails from people not in my contacts list and is older than 2 days
我正在使用基于此 here 的脚本来自动存档超过 7 天且未加星标的电子邮件。已加星标的电子邮件会一直保留在收件箱中,直到取消加星标为止,此时超过 7 天的电子邮件符合存档规则。
我的实际脚本:
function GmailArchive() {
var batchSize = 100 // Process up to 100 threads at once
var threads = GmailApp.search('label:"inbox" -label:"starred" older_than:7d');
for (j = 0; j < threads.length; j+=batchSize) {
GmailApp.moveThreadsToArchive(threads.slice(j, j+batchSize));
}
}
我想做的是在脚本中设置一个类似的并行函数,用于存档超过 1 天的电子邮件以及不在我的 google 联系人中的电子邮件。如果我们可以避免必须应用一个很棒的标签,那么没有什么大不了的。
到目前为止我的想法:
检查 getTo()
getCc()
或 getBcc()
字段,如果其中任何一个字段中有多个地址超过 2 天则存档。
var thread = GmailApp.getInboxThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getTo()); // log the recipient of message
我不确定这个 return 去哪里了,Logger.log?那是文件还是控制台?我如何捕获 return 并在 if >1 中使用它然后存档,否则继续下一个 message/thread 等直到它用完 messages/threads 等并退出。
我没有接受过正规的编码培训,我正在查看的 apologies.The 参考 material 是 here。
对于初学者,我建议您先查看整个Google Apps Script documentation,这样事情会更容易理解。
如果您使用 Apps 脚本 API 中的记录器 class,Logger.log 将是控制台消息。在大多数编程语言中,您可以通过将函数调用分配给变量或仅在操作中使用函数调用来捕获方法的 return 值。
结合使用 Gmail 和联系人脚本 API,我想到的一种方法是检索所有早于 1 天的收件箱电子邮件。
循环到每封电子邮件,然后通过 getFrom()
then use the email retrieved to getContactsByEmailAddress()
检索发件人的电子邮件地址。如果它 return 为空,则将电子邮件存档。
var threads = GmailApp.search('label:"inbox" older_than:1d');
for (j = 0; j < threads.length; j+=batchSize) {
/* If (getContactsByEmailAddress('address from getFrom()') = null)
GmailApp.moveThreadsToArchive(threads.slice(j, j+batchSize)) */
}
我正在使用基于此 here 的脚本来自动存档超过 7 天且未加星标的电子邮件。已加星标的电子邮件会一直保留在收件箱中,直到取消加星标为止,此时超过 7 天的电子邮件符合存档规则。
我的实际脚本:
function GmailArchive() {
var batchSize = 100 // Process up to 100 threads at once
var threads = GmailApp.search('label:"inbox" -label:"starred" older_than:7d');
for (j = 0; j < threads.length; j+=batchSize) {
GmailApp.moveThreadsToArchive(threads.slice(j, j+batchSize));
}
}
我想做的是在脚本中设置一个类似的并行函数,用于存档超过 1 天的电子邮件以及不在我的 google 联系人中的电子邮件。如果我们可以避免必须应用一个很棒的标签,那么没有什么大不了的。
到目前为止我的想法:
检查 getTo()
getCc()
或 getBcc()
字段,如果其中任何一个字段中有多个地址超过 2 天则存档。
var thread = GmailApp.getInboxThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getTo()); // log the recipient of message
我不确定这个 return 去哪里了,Logger.log?那是文件还是控制台?我如何捕获 return 并在 if >1 中使用它然后存档,否则继续下一个 message/thread 等直到它用完 messages/threads 等并退出。
我没有接受过正规的编码培训,我正在查看的 apologies.The 参考 material 是 here。
对于初学者,我建议您先查看整个Google Apps Script documentation,这样事情会更容易理解。
如果您使用 Apps 脚本 API 中的记录器 class,Logger.log 将是控制台消息。在大多数编程语言中,您可以通过将函数调用分配给变量或仅在操作中使用函数调用来捕获方法的 return 值。
结合使用 Gmail 和联系人脚本 API,我想到的一种方法是检索所有早于 1 天的收件箱电子邮件。
循环到每封电子邮件,然后通过 getFrom()
then use the email retrieved to getContactsByEmailAddress()
检索发件人的电子邮件地址。如果它 return 为空,则将电子邮件存档。
var threads = GmailApp.search('label:"inbox" older_than:1d');
for (j = 0; j < threads.length; j+=batchSize) {
/* If (getContactsByEmailAddress('address from getFrom()') = null)
GmailApp.moveThreadsToArchive(threads.slice(j, j+batchSize)) */
}