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()


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

  • 相关阅读:
    沈询:事务与分布式事务原理与实现
    c++ 幕客网
    Meet Dgraph — an open source, scalable, distributed, highly available and fast graph databas
    开发与系统管理----开发工具 左蓝
    奇虎360技术博客
    java 相关软件使用趋势
    长亭技术专栏 安全攻防技术分享
    tcp/ip RFC
    gentoo and arclinux
    孙鑫视频VC++深入详解学习笔记
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/11266701.html
Copyright © 2011-2022 走看看