zoukankan      html  css  js  c++  java
  • flask-mail(qq邮箱)

    from flask_mail import Mail,Message
    app.config['MAIL_SERVER']='smtp.qq.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_USE_TLS'] = True
    app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')
    app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')
    #此处应是QQ邮箱的授权码 app.config['FLASKY_MAIL_SUBJECT_PREFIX'] = '[Flasky]' app.config['FLASKY_MAIL_SENDER'] = 'Flasky Admin <1215475440@qq.com>' app.config['FLASKY_ADMIN'] = '1215475440@qq.com'

      发送

    @app.route('/',methods=['GET','POST'])
    def index():
    msg = Message(subject="helloworld", sender='1215475440@qq.com', recipients=['1808863623@qq.com'])
    msg.html = "testinghtml"
    mail.send(msg)

     异步发送邮件

    def send_async_email(app,msg):
        with app.app_context():
            mail.send(msg)
    
    def send_email(to, subject, template, **kwargs):
        msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
                      sender=app.config['FLASKY_MAIL_SENDER'], recipients=[to])
        msg.body = render_template(template + '.txt', **kwargs)
        msg.html = render_template(template + '.html', **kwargs)
        thr = Thread(target=send_async_email,args=[app,msg])
        thr.start()
        return thr
    

      

  • 相关阅读:
    Git标签使用技巧
    Git入门基本概述
    过滤器+缓存在.NET5WebApi项目中的简单使用
    在.NET5中 使用JWT鉴权授权
    Git常用开发命令
    时间戳的实际使用
    两个日期字段相减,进行计算
    MQ的理论理解
    第一周学习C语言的总结!
    问题(the question)
  • 原文地址:https://www.cnblogs.com/liushaocong/p/7417992.html
Copyright © 2011-2022 走看看