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')
  • 相关阅读:
    python面向对象(一)
    ls和cd命令详解
    SHELL 中的变量
    Shell基础
    Python版飞机大战
    Python模块制作
    Linux的cut命令
    Linux中的wc命令
    Ubuntu系统下adb devices 不能显示手机设备
    app耗电量测试工具--PowerTutor
  • 原文地址:https://www.cnblogs.com/w770762632/p/8877557.html
Copyright © 2011-2022 走看看