2017-03-06 34 views
1

我第一次使用Google Apps腳本,並試圖以編程方式簡單更新我在Gmail中的休假回覆,作爲Google Apps腳本的第一項測試。如何使用Google Apps腳本以編程方式更新電子郵件假期回覆?

我在這裏以下文件:https://developers.google.com/gmail/api/v1/reference/users/settings/updateVacation

而且我已經寫了:

function updateAutoResponse(){ 
    Gmail.Users.Settings.updateVacation('me', { 
     "enableAutoReply": true, 
     "responseSubject": "I am not here...", 
     "responseBodyPlainText": "I am not here...", 
     "responseBodyHtml": "I am not here...", 
     "restrictToContacts": false, 
     "restrictToDomain": false  
    }); 
} 

不幸的是,我得到一個錯誤,它似乎編譯後。解析錯誤(第65行,文件「代碼」)

我已經在高級Google服務以及Google API控制檯中啓用了Gmail API,所以我認爲這是某處的語法問題。

任何想法都會超級有用。謝謝!

回答

0

這是一個簡單的解決:

function updateAutoResponse(){ 
    Gmail.Users.Settings.updateVacation(
     { 
     "enableAutoReply": true, 
     "responseSubject": "Test", 
     "responseBodyHtml": "Testing script, not actually gone", 
     "restrictToContacts": false, 
     "restrictToDomain": false 
     }, 
     'me' 
    ); 
} 

userId是第二個參數,而不是第一個。它不是寫在文檔中,但是如果您允許Apps腳本自動完成向您顯示語法,則說明updateVacation(VacationSettings resource, String userId) : VacationSettings

此外,不知道這是否有任何影響,但我很確定提供responseBodyHtmlresponseBodyPlainText看起來沒有意義,因爲它們填充完全相同的點。如果你不需要HTML,你可以使用PlainText,但是如果你想格式化,你可以使用HTML,並且每當收件人不接受HTML時將使用PlainText(格式化將被刪除)

+0

非常感謝!這工作! – dunkhippo33

相關問題