Azi*_*ode 25 gmail google-apps-script
我创建了一个Google Apps脚本,用于检查电子邮件是否包含附件,然后将其发送到另一个电子邮件地址.
它工作正常,但我想创建一个触发器,一旦新电子邮件到达收件箱就会启动脚本.
我已经能够创建一个每小时启动脚本的触发器,但这不是我想要的
Azi*_*ode 31
经过一些研究和其他谷歌应用程序脚本开发人员的一些帮助,最好的解决方案是使用Gmail过滤系统和时间驱动触发器的组合.
因此,基本上对于普通的Gmail帐户,文档中提到的计算时间为1小时,请参阅此处的参考.
所以我做的是我设置了一个过滤器,为需要处理的传入电子邮件添加一个Label和一个星号.
在我的脚本中,我在数组中添加标签,我遍历标签数组,以便我只处理所需的电子邮件,而不是整个收件箱.
处理完毕后,脚本会从已处理的电子邮件中删除星标.
这样您就不会失去宝贵的计算时间,也不会达到每日限制.
然后我设置一个每10分钟运行一次的时间驱动触发器.
您还可以设置时间驱动触发器,每天向您发送"失败摘要",以便您可以查看脚本出现的问题并修复必须修复的内容.
Mat*_*ens 10
该答案改编自@AziCode的答案,但包含代码。
\n解决方案的组成部分:
\nHere\xe2\x80\x99s 是您的 Google Apps 脚本项目中的代码(您必须授予脚本访问 GMail 收件箱的权限):
\n// Configure this trigger to run often\n// (*how* often depends on the desired response time *and* how willing you are to risk hitting Google Apps Script\xe2\x80\x99s rate limits;\n// 10 minutes is probably good)\nfunction triggerScriptForEmail() {\n const threads = GmailApp.search(\'is:starred label:"<your desired label>"\');\n\n for (const thread of threads) {\n const messages = thread.getMessages()\n\n for (const message of messages) {\n // we know the thread *has* starred messages, but not *all* messages are necessarily starred\n if (message.isStarred()) {\n // THE CODE SPECIFIC TO YOUR CASE GOES HERE\n // THEN...\n message.unstar()\n }\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
18517 次 |
| 最近记录: |