zoukankan      html  css  js  c++  java
  • python

    # -*- coding:utf-8 -*-

    '''
    @project: Voctest
    @author: Jimmy
    @file: sendMail.py
    @ide: PyCharm Community Edition
    @time: 2018-11-15 17:14
    @blog: https://www.cnblogs.com/gotesting/

    '''

    import os
    import smtplib
    import time
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from Common.log import Log
    from Config.globalConfig import report_path


    logger = Log()
    # 配置收发件人
    recv_address = ['641969198@qq.com']
    # 163的用户名和密码
    send_addr_name = 'jxy641969198@163.com'
    send_addr_pswd = 'jiaxy19920319'


    class SendMail:
    def __init__(self, recver=None):
    """接收邮件的人:list or tuple"""
    if recver is None:
    self.sendTo = recv_address
    else:
    self.sendTo = recver

    def get_report(self):
    """获取最新测试报告"""
    lists = os.listdir(report_path)
    lists.sort()
    send_report = lists[-1]
    print('The send report name: {0}'.format(send_report))
    return send_report

    def take_messages(self):
    """生成邮件的内容,和html报告附件"""
    report = self.get_report()
    self.msg = MIMEMultipart()
    self.msg['Subject'] = 'VOC自动化测试报告'
    self.msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z')

    with open(os.path.join(report_path, report), 'rb') as f:
    mailbody = f.read()
    html = MIMEText(mailbody, _subtype='html', _charset='utf-8')
    self.msg.attach(html)

    # html附件
    att1 = MIMEText(mailbody, 'base64', 'gb2312')
    att1["Content-Type"] = 'application/octet-stream'
    att1["Content-Disposition"] = 'attachment; filename="VocAutoTestReport.html"'
    self.msg.attach(att1)

    def send(self):
    """发送邮件"""
    self.take_messages()
    self.msg['from'] = send_addr_name
    try:
    smtp = smtplib.SMTP('smtp.163.com', 25)
    smtp.login(send_addr_name, send_addr_pswd)
    smtp.sendmail(self.msg['from'], self.sendTo, self.msg.as_string())
    smtp.close()
    logger.log_info("发送邮件成功")
    except Exception:
    logger.log_error('发送邮件失败')
    raise
  • 相关阅读:
    C++纯虚函数调用
    C++编译期数据结构 在不同的地方声明全局数组的初始值
    用虚拟机把ubuntu安装到TF卡上
    点击a链接打开第三方页面变成下载页面问题
    SRAM和DRAM的区别
    真值表生成逻辑表达式程序
    大端 小端
    vhdl rising_edge(clk) (clk'event and clk='1')的区别
    ROM、RAM、DRAM、SRAM、FLASH的区别
    同一个主机头的多域名绑定多个ssl证书的方法
  • 原文地址:https://www.cnblogs.com/gotesting/p/9965249.html
Copyright © 2011-2022 走看看