zoukankan      html  css  js  c++  java
  • day12_框架二sendmail_new.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.to = to # 接收者的邮箱地址
    self.cc = cc # 抄送邮件
    self.subject = subject # 邮件标题
    self.contents = contents # 邮件正文
    self.attachments = attachments # 附件
    self.user = user # 发送者邮箱
    self.password = password # 发送者邮箱密码
    self.host = host # 邮箱服务器

    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:pythonyz-codeday12fuck_rf eporthtml'
    y = SendMail(user, password, host, to, cc, subject, contents)
    y.send_mail()
  • 相关阅读:
    求解奖学金问题--贪心
    装饰模式(Decorator Pattern)
    组合模式(Composite Pattern)
    Java基础:容器
    DatabaseMetaData类
    Java命名规范
    MyEclipse快捷键
    工厂模式(Factory)
    单例模式详解以及需要注意的地方(Singleton)
    SpringBoot启动流程与源码
  • 原文地址:https://www.cnblogs.com/laosun0204/p/8645337.html
Copyright © 2011-2022 走看看