-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_sender.py
37 lines (31 loc) · 1.29 KB
/
email_sender.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
from email_composer import EmailComposer
class EmailSender:
def __init__(self):
self.email_composer = EmailComposer()
def send_first_email(self, service, people):
thread_ids = []
for i in range(len(people)):
body = self.email_composer.first_email_body(people, i)
message = self.send_email(service, body)
thread_id = message['threadId']
thread_ids.append(thread_id)
return thread_ids
def send_second_email(self, service, people, thread_id):
thread = service.users().threads().get(userId="me", id=thread_id).execute()
body = self.email_composer.second_email_body(people, thread_id, thread)
message = self.send_email(service, body)
return message['threadId']
def send_third_email(self, service, people, thread_id):
thread = service.users().threads().get(userId="me", id=thread_id).execute()
body = self.email_composer.third_email_body(people, thread_id, thread)
message = self.send_email(service, body)
return message['threadId']
@staticmethod
def send_email(service, body):
try:
message = (service.users().messages().send(userId="me", body=body).execute())
print('Message Id: %s' % message['id'])
return message
except Exception as error:
print('An error occurred: %s' % error)
return {}