Gmail Vacation Responder

144 views
Skip to first unread message

Anna Ulmer

unread,
May 21, 2022, 10:50:34 AM5/21/22
to Google Apps Script Community
I'm hoping someone can share some info on how to add a script to auto set my gmail vacation responder to turn on and off each day at set times. I've looked on Stack Overflow and found a script with the full responder message, which I don't need. I just need to have it turn on and off. Any help is so much appreciated!!

Clark Lind

unread,
May 21, 2022, 1:17:54 PM5/21/22
to Google Apps Script Community

Clark Lind

unread,
May 21, 2022, 1:52:36 PM5/21/22
to Google Apps Script Community
After adding the advanced Gmail API (under the services menu), something like the following (untested) should work. You may have to play around with it to suit your needs:

function setVacation() {

//example set vacation for May 23 5pm to May 24 6am
  var startTime = Math.floor(new Date('5/23/2022 17:00:00').getTime() / 1000)
  var endTime =   Math.floor(new Date('5/24/2022 06:00:00').getTime() / 1000)
     
  do {
    var vacayUpdate = Gmail.users.settings.updateVacation('me', {
    "enableAutoReply": true,
    "responseSubject": "I'm Out!",
    "responseBodyPlainText": "I'm out of the office, please contact XYZ",
    // "responseBodyHtml": string, //not used unless you want to build a fancy html email
    "restrictToContacts": false,  //set as needed
    "restrictToDomain": true,    //set as needed
    "startTime": startTime,    
      "endTime": endTime
    });
    console.log(vacayUpdate);   //I don't know what this will spit out :)
  });
Reply all
Reply to author
Forward
0 new messages