#coding=utf-8 from email.headerimportHeader from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import smtplib, datetime
msg = MIMEMultipart()
def alarmMail(receriver,picname): #Mail server conf mail_sender = 'robot@eliyar.biz' mail_sender_password = 'automail917' SMTP_server = 'smtp.exmail.qq.com' server = smtplib.SMTP(SMTP_server) server.login(mail_sender,mail_sender_password)
#mail body body_txt = MIMEText('Some one invaded the house, please cheak up the attachments') msg.attach(body_txt)
#Add four attachment for i in range(1,5): att = MIMEText(open('imgs/%s_%i.jpg' %(picname,i) , 'rb').read(), 'base64', 'gb2312') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename="%s_%i.jpg"'%(picname,i) msg.attach(att)
#Send mail server.sendmail(msg['from'], msg['to'], msg.as_string()) server.close() print('Successfully send mail to %s' %receriver)