本文介绍了Gmail服务事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当新电子邮件到达收件箱时,我都希望运行处理功能.我正在查看 https://developers.google.com/apps-script /guides/triggers/events .我没有看到在收到电子邮件时触发事件的方法.我想念什么吗?
I would like to run a processing function whenever a new email arrives in my inbox. I'm looking at https://developers.google.com/apps-script/guides/triggers/events . I don't see a way to trigger an event when an email arrives. Am I missing something?
推荐答案
Apps脚本中没有基于电子邮件的触发器.作为不完善的解决方法,您可以每5分钟运行一个脚本并处理在最新间隔内到达的消息.这是一个基于此帖子的示例:
There are no email-based triggers in Apps Script, as Serge insas said. As an imperfect workaround, you can run a script every 5 minutes and process the messages that arrived within the latest interval. Here is an example, based on this post:
function checkEmail() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var date = new Date();
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
threads[i].reply("This is auto-reply for demonstration; you probably want to do something else here.");
}
}
这篇关于Gmail服务事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!