在收到的电子邮件中触发的Google Gmail脚本 [英] Google gmail script that triggers on incoming email
问题描述
我一直在阅读 gmail插件.它们具有上下文触发,可在您打开电子邮件时触发.
I've been reading through gmail addons. They have contextual triggers that trigger when you open an email.
我收到电子邮件后是否可以触发服务?我能找到的最好的是unconditional
,但这仅在打开电子邮件时触发.
Is it possible to trigger a service when an email is received by me? Best I can find is unconditional
but that only triggers when the email is opened.
推荐答案
You can't create a trigger for every email, however you can do something similar as described in this answer.
例如,您可以:
-
设置一个过滤器,在要处理的传入电子邮件上添加特殊标签.
Set up a filter that puts a special label on incoming emails that you want to process.
设置一个重复发生的脚本,该脚本每10分钟甚至每分钟运行一次.在脚本中,您可以提取所有具有给定标签的电子邮件,并进行相应处理,并在完成后删除标签.
Set up a reoccurring script that runs every 10 minutes, or even every minute. In the script, you can pull all of the emails that have the given label, and process them accordingly, removing the label when you are done.
function processEmails() {
var label = GmailApp.getUserLabelByName("Need To Process");
var threads = label.getThreads();
for (var i = threads.length - 1; i >= 0; i--) {
//Process them in the order received
threads[i].removeLabel(label).refresh();
}
}
然后您可以在基于时间的触发器上进行设置它会按照您希望的频率运行.
You can then set this on a time based trigger to have it run as often as you would like.
如果要跟踪已处理的电子邮件,可以创建另一个已处理"标签,并在完成处理后将其添加到邮件中.
If you want to keep track of the emails you have processed, you can create another "processed" label and add that to the message when you are done processing.
这篇关于在收到的电子邮件中触发的Google Gmail脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!