Gmail service events?

爱⌒轻易说出口 提交于 2019-12-23 03:48:45

问题


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?


回答1:


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.");
  }
}


来源:https://stackoverflow.com/questions/46692451/gmail-service-events

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