-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_mail.py
40 lines (30 loc) · 1016 Bytes
/
send_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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
def send(filename):
from_add = 'bikal123@gmail.com'
to_add = 'bikal456@gmail.com'
subject = "Finance Stock Report"
# header
msg = MIMEMultipart()
msg['From'] = from_add
msg['To'] = to_add
msg['Subject'] = subject
# body
body = "<b>Today's Fianance Report Attached.</b>"
msg.attach(MIMEText(body, 'html'))
my_file = open(filename, 'rb')
# attach file
part = MIMEBase('application', 'octet-stream')
part.set_payload((my_file).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename= ' + filename)
msg.attach(part)
message = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('bikal123@gmail.com', 'password')
server.sendmail(from_add, to_add, message)
server.quit()