• python发送邮件


    def send_mail(smtp_dict, report):
        """用于将测试报告发送到邮箱
        :param
        smtp_dict = {
            "smtp_server": "发送邮件的smtp ex:smtp.126.com",
            "send_user": "发送邮件的邮箱 ex:am1122@126.com",
            "send_pwd": "发送邮件的邮箱密码 ex:mima",
            "sender": "发件人邮箱用于显示收到邮件中的发件人 ex:am1122@126.com",
            "receiver": "收件人邮箱 ex:zhangmin@hidtest.cn",多个收件人可以写成list
            "subject": "邮件主题 ex:自动化测试报告"
        }    
        """
    
        # 获取测试报告的内容
        file = open(report, "rb")
        mail_body = file.read()
        file.close()
        # 组装邮件内容
        msg = MIMEText(mail_body, 'html', 'utf-8')
        msg['Subject'] = Header(smtp_dict["subject"], 'utf-8')
        msg['From'] = smtp_dict["send_user"]
        # 发送邮件
        try:
            smtp = smtplib.SMTP()
            smtp.connect(smtp_dict["smtp_server"])
            smtp.login(smtp_dict["send_user"], smtp_dict["send_pwd"])
            smtp.sendmail(smtp_dict["sender"], smtp_dict["receiver"], msg.as_string())
        except smtplib.SMTPException as se:
            print("邮件发送失败!!")
            print(se)
  • 相关阅读:
    基于bootstrap分页
    encache学习教程
    java异常和spring事务注解
    JSP自定义标签开发入门
    spring junit
    vs与数据库连接查询
    winfrom文本文档打开
    面向对象 封装
    面向对象 概念
    DW 游记代码
  • 原文地址:https://www.cnblogs.com/ceshixuexi/p/8625459.html
Copyright © 2020-2023  润新知