Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you programmatically update an email vacation response using Google Apps Script?

I'm using Google Apps Script for the first time and am trying to simply update my vacation response in Gmail programmatically as a first test of Google Apps Script.

I'm following the documentation here: https://developers.google.com/gmail/api/v1/reference/users/settings/updateVacation

And I have written:

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

Unfortunately, I get an error after it appears to compile. Parse Error (line 65, file "Code")

I've enabled the Gmail API in Advanced Google Services as well as in the Google API Console, so I think this is a syntax issue somewhere.

Any thoughts would be super helpful. Thanks!

like image 424
dunkhippo33 Avatar asked Jul 26 '26 03:07

dunkhippo33


1 Answers

this is a simple fix:

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

The userId is the second argument, not the first. It's not written in the documentation, however if you allow Apps Script autocomplete to show you the syntax, it states updateVacation(VacationSettings resource, String userId) : VacationSettings.

Also, not sure if this has any impact, but I am pretty sure there is no point in providing both responseBodyHtml and responseBodyPlainText seeing as they fill the exact same spot. If you don't need the HTML, you can just use PlainText, but if you want formatting, you use HTML and PlainText will be used whenever the recipient does not accept HTML (formatting will just get removed)

like image 125
Vytautas Avatar answered Jul 30 '26 09:07

Vytautas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!