forked from Jefferson-Henrique/GetOldTweets-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailHandler.py
39 lines (28 loc) · 1 KB
/
emailHandler.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
import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email import encoders
# http://naelshiab.com/tutorial-send-email-python/
def send_email(subject, file_path, file_name):
fromaddr = "pythonnotification1@gmail.com"
toaddr = "lud291@mail.usask.ca"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = subject
body = "Python Notification"
msg.attach(MIMEText(body, 'plain'))
filename = file_name
attachment = open(file_path, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "3rpjlSPVjcp8")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()