python 发送邮件

作者在 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;'>&nbsp;&nbsp; congratalation,:</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;请查收!<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()
appium | 阅读 9344 次
文章评论,共0条
游客请输入验证码
浏览2354398次