作者在 2016-04-12 15:39:34 发布以下内容
import smtplib
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
class SendEmailReporter(object):
def SendMail(self,filename):
sender = 'mobile@139.com'
receiver = ['554646@qq.com','554646@qq.com']
subject = "test report"
smtpserver = 'SMTP.139.com'
EMAIL_PORT = '25'
username = '554646@139.com'
password = '554646'
files = "../testreport/"+filename
# 标题和文件正文
msgRoot = MIMEMultipart()
msgRoot['Subject'] = subject
text_msg = MIMEText("<html><body><p><span style='color: red;'> congratalation,:</span></p><p> 请查收!<br/></p></body></html>",'html',_charset="utf-8")
msgRoot.attach(text_msg)
#附件
att = MIMEText(open(files, 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="bruce.html"'
msgRoot.attach(att)
smtp = smtplib.SMTP()
smtp.connect(host=smtpserver,port=EMAIL_PORT)
smtp.login(username,password)
smtp.sendmail(sender,receiver,msgRoot.as_string())
smtp.quit()