澳门新葡亰网址下载python 发送邮件

by admin on 2020年1月17日
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>&nbsp;&nbsp; congratalation,:</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()

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图