zoukankan      html  css  js  c++  java
  • 邮件的操作

    from ProjVar.var import *
    import smtplib
    from email import encoders
    from email.mime.base import MIMEBase
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from email.header import Header
    from email.utils import formataddr
    
    def send_mail():
        mail_host="smtp.163.com"  #设置服务器
        mail_user="24234234234"    #用户名
        mail_pass="redfdfgfh1232"   #口令
        sender = '424242424@163.com'
        receivers = ['3123131@qq.com',"232323@qq.com"] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
        # 创建一个带附件的实例
        message = MIMEMultipart()
        message['From'] = formataddr(["this ia a test", "424242424@163.com"])
        message['To'] = ','.join(receivers)
        subject = '自动化测试执行报告'
        message['Subject'] = Header(subject, 'utf-8')
        message["Accept-Language"]="zh-CN"
        message["Accept-Charset"]="ISO-8859-1,utf-8,gbk"
        # 邮件正文内容
        message.attach(MIMEText('最新执行的自动化测试报告,请参阅附件内容!', 'plain', 'utf-8'))
    
        # 构造附件1,传送测试结果的excel文件
        att = MIMEBase('application', 'octet-stream')
        att.set_payload(open(ProjDirPath+"\testdata\data.xlsx", 'rb').read())
        att.add_header('Content-Disposition', 'attachment', filename=('gbk', '', "自动化测试报告.xlsx"))
        encoders.encode_base64(att)
        message.attach(att)
    
        try:
            smtpObj = smtplib.SMTP(mail_host)
            smtpObj.login(mail_user, mail_pass)
            smtpObj.sendmail(sender, receivers, message.as_string())
            print("邮件发送成功")
        except smtplib.SMTPException as e:
            print("Error: 无法发送邮件", e)
    
    if __name__ == "__main__":
        send_mail()


    一切技术都是为业务服务,脱离业务的技术一文不值!

  • 相关阅读:
    【转】WCF入门教程六[一个简单的Demo]
    【转】WCF入门教程五[WCF的通信模式]
    【转】WCF入门教程四[WCF的配置文件]
    【转】WCF入门教程三[WCF的宿主]
    【转】WCF入门教程二[WCF应用的通信过程]
    【转】WCF入门教程一[什么是WCF]
    【转】浅谈.net remoting 与webservice
    【转】Microsoft .Net Remoting之Remoting事件处理全接触
    egret升级经验记录
    cmder小技巧
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/11266701.html
Copyright © 2011-2022 走看看