zoukankan      html  css  js  c++  java
  • 人生苦短,我学python之python+selenium 发送邮件

    # coding:utf-8
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    import os
    def send_email(smtpserver,port,sender,psw,receiver):
        #发件服务器
        # smtpserver='smtp.qq.com'
        # #端口
        # port=465
        # sender="770762632@qq.com"
        # #QQ邮箱为授权码,其他邮箱为密码
        # psw="snjczicdivhcbcde"
        # receiver='770762632@qq.com'
        msg=MIMEMultipart()
        msg['subject']="自动化测试用例"
        msg['from']=sender
        msg['to']=receiver
        #当前脚本所在路径
        curpath=os.path.realpath(__file__)
        print curpath
        #获取当前脚本所在文件夹的路径
        filepath=os.path.dirname(curpath)
        print filepath
        fatpath=os.path.dirname(filepath)
        print fatpath
        reportpath=os.path.join(fatpath,'report')
        print reportpath
        report=os.path.join(reportpath,'report.html')
        print report
    
        b=open(report,'r')
        main_body=b.read()
        b.close()
        # 添加到附件
        at=MIMEText(main_body,'base64','utf-8')
        at["Content-Type"] = "application/octet-stream"
        at["Content-Disposition"] ='attachment; filename="test_report.html"'
        msg.attach(at)
        # 添加正文
        body=MIMEText(main_body,'html','utf-8')
        msg.attach(body)
        #写信流程
        smtp=smtplib.SMTP_SSL(smtpserver,port)
        smtp.login(sender,psw)
        smtp.sendmail(sender,receiver,msg.as_string())
        smtp.quit()
    send_email('smtp.qq.com',465,"770762632@qq.com","snjczicdivhcbcde",'770762632@qq.com')
  • 相关阅读:
    zedboard如何从PL端控制DDR读写(四)
    ZC706以太网扩展板接口
    软件测试作业3--Junit、hamcrest、eclemmat的安装和使用
    软件测试作业2
    软件测试作业1--描述Error
    安装Mysql 5.7.1
    Servlet生命周期+工作原理
    VS中工程的“依赖”,“库目录”,“包含目录”
    Linux C 重定向简单范例
    Java中关键字final用法
  • 原文地址:https://www.cnblogs.com/w770762632/p/8877557.html
Copyright © 2011-2022 走看看