-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreport_mailer.py
55 lines (47 loc) · 1.96 KB
/
report_mailer.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
44
45
46
47
48
49
50
51
52
53
54
55
import smtplib
import os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from datetime import date
from utils import Utils
class Mailer:
def send_mail(self, email_send):
utils = Utils()
email_user = utils.report_mailer["mail-id"]
email_password = utils.report_mailer["mail-password"]
subject = str(date.today())+'ZOOM RECORDINGS UPLOAD REPORT'
msg = MIMEMultipart()
msg['From'] = email_user
if isinstance(email_send,list):
msg['To'] = ','.join(email_send)
else :
msg['To'] = email_send
msg['Subject'] = subject
body = 'Successfully Uploaded Zoom recordings to Vimeo.The generated reportfile is attached below.'
msg.attach(MIMEText(body, 'plain'))
if os.path.isfile('error.txt'):
files=['outputfile.csv','error.txt']
for f in files:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(f,"rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
else:
f='outputfile.csv'
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(f,"rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, email_password)
server.sendmail(email_user, email_send, text)
print('\n'+' Mail Has Been Sent To {filename} '.format(filename=email_send).center(100,':'))
server.quit()