-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsuite_ooo.py
43 lines (36 loc) · 1.5 KB
/
gsuite_ooo.py
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
""" Begin for automated ooo reply (Gsuite) """
import sys
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/gmail.settings.basic',
'https://mail.google.com/']
"""'keyp12.p12' should be replaced with the path to your generated p12 key
'serviceaccount@gserviceaccount.com' should be replaced with the generated service gsuite account"""
SERVICE_ACCOUNT_FILE = 'keyp12.p12'
SERVICE_ACCOUNT_EMAIL = 'serviceaccount@gserviceaccount.com'
def out_reply(name, email):
''' gsuiste ooo reply function '''
credentials = ServiceAccountCredentials.from_p12_keyfile(
SERVICE_ACCOUNT_EMAIL,
SERVICE_ACCOUNT_FILE,
scopes=SCOPES)
out_of_office = {
'enableAutoReply': True,
'responseBodyHtml': "<p>Hi, I am no longer working at COMPANY.</p>"
"<p>Regards,</p> <p>{}</p>".format(
name),
'restrictToDomain': False,
}
credentials = credentials.create_delegated(email)
service = build('gmail', 'v1', credentials=credentials)
result = service.users().settings().updateVacation(
userId='me', body=out_of_office).execute()
return result
try:
sys_args_name = sys.argv[1]
sys_args_email = sys.argv[2]
out_reply(sys_args_name, sys_args_email)
except:
fullname_leaver = input('Full name leaver: ')
email_leaver = input('Email leaver: ')
out_reply(fullname_leaver, email_leaver)