Advertisement
RemcoE33

Update OutOfOffice

Jun 29th, 2021
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Global variable:
  2. const USER = 'user@company.com'
  3.  
  4. function readCurrentOutOfOffice(){
  5.   console.log(Gmail.Users.Settings.getVacation(USER))
  6. }
  7.  
  8. function outOfOfficeON() {
  9.  
  10.   //Creating the dates
  11.   const date = new Date().toISOString().split("T")[0]
  12.   const startTime = new Date(date).getTime()
  13.   const endTime = new Date(startTime + 172800000).getTime()
  14.  
  15.   console.log({
  16.     date,
  17.     startTime,
  18.     endTime
  19.   })
  20.  
  21.   //Build settings:
  22.   const settings = JSON.stringify({
  23.     restrictToContacts: false,
  24.     enableAutoReply: true,
  25.     responseBodyHtml: `<div dir="ltr">Hi mailer,<div><br></div><div>I&#39;m currently not in the office because i like diving with sharks. If i&#39;m not eaten alive i will get back to you first thing tomorrow!</div><div><br></div><div>Greetings,</div><div>RemcoE33</div></div>`,
  26.     responseSubject: 'I\'m not around',
  27.     endTime: endTime.toString(),
  28.     startTime: startTime.toString()
  29.   })
  30.  
  31.   const response = Gmail.Users.Settings.updateVacation(settings, USER)
  32.  
  33.   console.log({
  34.     type: 'Turning on',
  35.     response
  36.   })
  37. }
  38.  
  39. function outOfOfficeOff(){
  40.   const settings = JSON.stringify({
  41.     enableAutoReply: false
  42.   })
  43.  
  44.   const response = Gmail.Users.Settings.updateVacation(settings, USER)
  45.  
  46.   console.log({
  47.     type: 'Turning off',
  48.     response
  49.   })
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement