-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.py
38 lines (32 loc) · 1.12 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
import smtplib
'''
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
'''
from email import *
fromadr = input("Enter Source Address")
toadr= input("Enter destination Address")
message = MIMEMultipart()
message['From'] = fromadr
message['To'] = toadr
message['Subject'] = "Test python email with attachment"
message_body = "Sample test python mail"
message.attach(MIMEText(message_body, 'plain'))
filename=input("Enter the file name")
fileloc = input("Enter Attachment File location with file name and extension")
attachment = open(fileloc, "rb")
link = MIMEBase('application', 'octet-stream')
link.set_payload((attachment).read())
encoders.encode_base64(part)
link.add_header('Content-Disposition', "attachment; filename= %s" % filename)
message.attach(link)
smtp=input("Enter the smtp link through which you would like to send the mail")
server = smtplib.SMTP(smtp, 587)
server.starttls()
password=input("Enter your password")
server.login(fromaddr, password)
text = message.as_string()
server.sendmail(fromadr, toadr, text)
server.quit()