-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOutOfOffice.js
More file actions
63 lines (49 loc) · 1.68 KB
/
OutOfOffice.js
File metadata and controls
63 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Created by: RemcoE33
https://github.com/RemcoE33/apps-script-codebase
1. Set you out of office inside Gmail Settings to use as template.
2. Check GmailAPI under services inside the script editor.
3. Run 'readCurrentOutOfOffice' and copy the HTML from the log.
4. Change the HTML on 'responseBodyHtml' with your copied html.
5. Now you can set 'outOfOfficeON' and 'outOfOfficeOff' on a trigger of your choose.
*/
//Global variable:
const USER = 'user@company.com'
function readCurrentOutOfOffice(){
console.log(Gmail.Users.Settings.getVacation(USER))
}
function outOfOfficeON() {
//Creating the dates
const date = new Date().toISOString().split("T")[0]
const startTime = new Date(date).getTime()
const endTime = new Date(startTime + 172800000).getTime()
console.log({
date,
startTime,
endTime
})
//Build settings:
const settings = JSON.stringify({
restrictToContacts: false,
enableAutoReply: true,
responseBodyHtml: `<div dir="ltr">Hi mailer,<div><br></div><div>I'm currently not in the office because i like diving with sharks. If i'm not eaten alive i will get back to you first thing tomorrow!</div><div><br></div><div>Greetings,</div><div>RemcoE33</div></div>`,
responseSubject: 'I\'m not around',
endTime: endTime.toString(),
startTime: startTime.toString()
})
const response = Gmail.Users.Settings.updateVacation(settings, USER)
console.log({
type: 'Turning on',
response
})
}
function outOfOfficeOff(){
const settings = JSON.stringify({
enableAutoReply: false
})
const response = Gmail.Users.Settings.updateVacation(settings, USER)
console.log({
type: 'Turning off',
response
})
}