一旦电子邮件进入收件箱,如何触发 Google Apps 脚本? [英] How to trigger a Google Apps Script once an email get in the inbox?

查看:23
本文介绍了一旦电子邮件进入收件箱,如何触发 Google Apps 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 Google Apps 脚本,用于检查电子邮件是否包含附件,然后将其发送到另一个电子邮件地址.

I have created a Google Apps Script that checks if an email has an attachment then send it to another email address.

它工作正常,但我想创建一个触发器,以便在新电子邮件到达收件箱时立即启动脚本.

It's working fine, but I would like to create a trigger that would launch the script as soon as a new email arrives in the inbox.

我已经能够创建一个每小时启动脚本的触发器,但这不是我想要的

I have been able to create a trigger that launch the script every hour, but it's not what I want

推荐答案

经过一些研究和其他 google-apps-script 开发人员的帮助,最好的解决方案是结合使用 Gmail 过滤系统和时间-驱动触发.

After some research and some help from other google-apps-script developers, the best solution is to use a combination of Gmail filtering system in addition to a time-driven-trigger.

因此,对于普通的 Gmail 帐户,基本上有 1 小时/天的计算时间,如上所述 在文档中.

So basically for a normal Gmail account there is a 1 hour/day computing time as mentioned in the documentation.

所以我所做的是设置一个过滤器,为需要处理的传入电子邮件添加标签和星号.

So what I did is set up a filter that adds a Label and a star to the incoming emails that need to be processed.

在我的脚本中,我将标签添加到一个数组中,并遍历标签数组,以便只处理所需的电子邮件,而不是整个收件箱.

In my script I add the Labels in an array, I loop over the array of labels so that I process only the desired emails and not the whole inbox.

处理后,脚本会从处理的电子邮件中删除星标.

Once processed, the script removes the star from the processed email.

这样您就不会失去宝贵的计算时间,也不会达到每日限制.

This way you don't lose your precious compute time, and you don't reach the daily limit.

然后我设置了一个每 10 分钟运行一次的时间驱动触发器.

I then set a time driven trigger that runs every 10 minutes.

您还可以设置时间驱动触发器,每天向您发送故障摘要";这样您就可以看到脚本出了什么问题并修复了必须修复的内容.

You can also set up the time driven trigger to send you a daily "Summary of failures " so that you can see what went wrong with your script and fix what has to be fixed.

这篇关于一旦电子邮件进入收件箱,如何触发 Google Apps 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆