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

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

问题描述

我创建了Google Apps脚本,用于检查电子邮件是否有附件,然后将其发送到其他电子邮件地址。

工作正常,但我想创建一个触发器,一旦新电子邮件到达收件箱,就会启动该脚本。



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

经过一些研究和其他谷歌应用程序脚本开发人员的帮助后,最好的解决方案是使用Gmail过滤系统的组合,除了时间驱动触发。



因此,基本上对于一个正常的Gmail帐户,有一个1小时的计算时间文档请参阅此处



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



在我的脚本中,我将标签添加到数组中,我遍历了标签数组,以便仅处理期望的电子邮件而不是整个收件箱。



处理完毕后,脚本会从处理后的电子邮件中删除星星。



这样您就不会失去宝贵的计算时间,而且您也不会达到每日限额。

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



您可以还设置了时间驱动触发器,每天向您发送故障摘要,以便您可以查看脚本出了什么问题并修复必须修复的问题。

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

解决方案

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.

So basically for a normal Gmail account there is a 1 hour computing time as mentioned in the documentation See reference here.

So what I did is that I 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.

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天全站免登陆