2017-10-11 83 views
1

我希望在新郵件到達收件箱時運行處理功能。我正在看https://developers.google.com/apps-script/guides/triggers/events。當電子郵件到達時,我沒有看到觸發事件的方法。我錯過了什麼嗎?Gmail服務事件?

+1

不,你不是。現在在應用程序腳本中沒有這種觸發器。 –

+0

您可以使用一些解決方法,例如標記新電子郵件,然後使用'GmailApp'通過標籤輪詢消息的數量並進行迭代。這並不理想,但可以幫助您獲得所需的信息。 – Brian

回答

2

正如Serge insas所說,Apps腳本中沒有基於電子郵件的觸發器。作爲不完善的解決方法,您可以每5分鐘運行一次腳本,並處理在最近的時間間隔內到達的消息。這裏是一個例子,根據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."); 
    } 
}