-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.py
39 lines (30 loc) · 1001 Bytes
/
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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
sender_email = "[email protected]"
rec_email = "[email protected]"
password = input(str("Enter passrord:"))
message = MIMEMultipart()
message['From'] = sender_email
message['to'] = rec_email
message['Sub']= "hi"
body = "Body"
message.attach(MIMEText(body,'plain'))
filename ="attendence.csv"
attachment = open(filename,"rb")
p = MIMEBase('application','octet-stream')
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition',"attachment; filename=%s" % filename)
message.attach(p)
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(sender_email, password)
print("login email")
text = message.as_string()
server.send_message(message)
server.quit()
#server.sendmail(sender_email, rec_email, message)
#print("Email has been send to ", rec_email)