• day12_框架一sendmail.py代码


    import yagmail
    # 发送邮件,user为发送邮件的邮箱名,password为邮箱授权码,host为邮箱服务器,cc为抄送的邮箱
    # to为接收者的邮箱多个邮箱用list,subject为邮件标题,contents为邮件正文,attachments为邮件带的附件(即生成的最新的报告)
    class Sendmail(object):
    def __init__(self,user,password,host,to,cc,subject,contents,attachments=None):
    self.user = user # 发送者邮箱
    self.password = password # 发送者邮箱授权码
    self.host = host # 邮箱服务器
    self.to = to # 接收者的邮箱地址
    self.cc = cc # 抄送邮件
    self.subject = subject # 邮件标题
    self.contents = contents # 邮件正文
    self.attachments = attachments # 附件

    def send_mail(self):
    yag = yagmail.SMTP(user=self.user, password=self.password, host=self.host)
    try:
    yag.send(to=self.to,cc=self.cc,subject=self.subject,contents=self.contents,attachments=self.attachments)
    print('邮件发送成功!')
    except Exception as e:
    print('邮件发送出错,请检查!错误是%s' % e)

    if __name__ == '__main__':
    user = 'jiangshuihengliu@126.com' # 发件箱
    password = 'a123456' # 邮箱授权码
    host = 'smtp.126.com' # 邮件服务器
    to = 'sunshujiang184@163.com' # 收件邮箱
    cc = ["174596537@qq.com"] # 抄送邮箱
    subject = '测试报告' # 邮件标题
    contents = '这是测试' # 附件内容
    attachments = r'D:jxzapi_auto eportshtml' # 附件
    y = Sendmail(user, password, host, to, cc, subject, contents)
    y.send_mail()
  • 相关阅读:
    Jmeter非GUI、GUI模式压测生成测试报告
    测试轮播banner
    Jmeter如何监控服务器CPU、内存、i/o等资源
    java基础(三)
    用python从符合一定格式的txt文档中逐行读取数据并按一定规则写入excel(openpyxl支持Excel 2007 .xlsx格式)
    L2-011. 玩转二叉树
    L2-010. 排座位
    L2-008. 最长对称子串
    L2-009. 抢红包
    L2-006. 树的遍历
  • 原文地址:https://www.cnblogs.com/laosun0204/p/8616085.html
Copyright © 2020-2023  润新知