zoukankan      html  css  js  c++  java
  • Python 发送Email

    使用Python自动发送邮件

    import smtplib
    import time
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText 
    from email.mime.application import MIMEApplication
    
    
    #邮件发送的用户名和密码  常识:第三方授权码
    _user = user
    _pwd = pwd
    
    now = time.strftime('%Y-%m-%d_%H_%M_%S')#获取时间戳
    
    class sendEmail:
        def send_email(self,email_to,filepath):
            #email_to  收件方
            #filepath 你要发送附件的地址
            #如名字所示Multipart就是分多个部分
            msg = MIMEMultipart()
            msg["Subject"] = now+"_Webservice Test Report --from Steve"
            msg["From"]  = _user
            msg["To"]   = email_to
    
            #---这是文字部分---
            part = MIMEText("这次是自动化测试结果,请查收!")
            msg.attach(part)
    
            #---这是附件部分---
            part = MIMEApplication(open(filepath,'rb').read())
            part.add_header('Content-Disposition', 'attachment', filename=filepath)
            msg.attach(part)
            s = smtplib.SMTP_SSL("smtp.qq.com", timeout=30)#连接smtp邮件服务器,端口默认是25
            s.login(_user, _pwd)#登陆服务器
            s.sendmail(_user, email_to, msg.as_string())#发送邮件
            s.close()
  • 相关阅读:
    hdu 4474 大整数取模+bfs
    Codeforces Mafia
    hdu 4750 Count The Pairs(并查集)
    zoj 3659 Conquer a New Region(并查集)
    zoj 3656
    poj 3678 Katu Puzzle(Two Sat)
    UVa 11235 RMQ
    hdu 4768 Flyer (二分)
    hdu 4762 Cut the Cake概率公式
    Ural 1046 Geometrical Dreams(解方程+计算几何)
  • 原文地址:https://www.cnblogs.com/666666pingzi/p/10410068.html
Copyright © 2011-2022 走看看