-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_MAIL.py
34 lines (29 loc) · 1.08 KB
/
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
import smtplib, genkey
from os.path import basename
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from email.MIMEBase import MIMEBase
from email.mime.application import MIMEApplication
def send_mail(sender,password,recpnt,subject,body,img,files):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender, password)
msg=MIMEMultipart()
msg['From']=sender
msg['To']=recpnt
msg['Subject']=subject
genkey.encryptIT(body,img)
msg.attach(MIMEText(genkey.encrypted,'plain'))
fp = open('output.png', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header('Content-Disposition', 'inline', filename='output.png')
msg.attach(msgImage)
for f in files:
with open(f, "rb") as fil:
part = MIMEApplication(fil.read(),Name=basename(f))
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
msg.attach(part)
server.sendmail(sender, recpnt, msg.as_string())
server.quit()