-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmail.py
51 lines (48 loc) · 2.08 KB
/
mail.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
from imports import *
def send_fail(receiver_address):
mail_content_file = open('fail_body.txt')
sender_address = 'YOUR_EMAIL_HERE'
sender_pass = 'PASS'
# Setup the MIME
message = MIMEMultipart()
message['From'] = "Shanay Ghag and Saarth Deshpande"
message['To'] = receiver_address
message['Subject'] = 'Chapterwise Summarization'
# The subject line
# The body and the attachments for the mail
message.attach(MIMEText(mail_content_file.read(), 'plain'))
session = smtplib.SMTP('smtp.gmail.com', 587) # use gmail with port
session.starttls() # enable security
session.login(sender_address, sender_pass) # login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Fail Mail Sent')
def send_mail(zipfile_name, receiver_address):
mail_content_file = open('mail_body.txt')
sender_address = 'YOUR_EMAIL_HERE'
sender_pass = 'PASS'
# Setup the MIME
message = MIMEMultipart()
message['From'] = "Shanay Ghag and Saarth Deshpande"
message['To'] = receiver_address
message['Subject'] = 'Chapterwise Summarization'
# The subject line
# The body and the attachments for the mail
message.attach(MIMEText(mail_content_file.read(), 'plain'))
attach_file_name = f'{zipfile_name}'
attach_file = open(attach_file_name, 'rb') # Open the file as binary mode
payload = MIMEBase('application', 'zip')
payload.set_payload(attach_file.read())
encoders.encode_base64(payload) # encode the attachment
payload.add_header('Content-Disposition', f'attachment; filename= {attach_file_name}')
# add payload header with filename
message.attach(payload)
# Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587) # use gmail with port
session.starttls() # enable security
session.login(sender_address, sender_pass) # login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')