Gmail service events?

Deadly 提交于 2019-12-07 07:32:25

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.");
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!