zoukankan      html  css  js  c++  java
  • 2018.4.24 flask_mail使用

    #!/flask/bin/python
    # -*- coding: utf-8 -*-
    
    from threading import Thread
    from flask import Flask
    from flask_mail import Mail,Message
    import traceback
    from flask import render_template
    
    app = Flask(__name__)
    
    app.config["MAIL_SERVER"] = "smtp.163.com"
    app.config["MAIL_PORT"] = 465
    app.config["MAIL_USE_SSL"] = True
    app.config["MAIL_USERNAME"] = "@163.com"
    app.config["MAIL_PASSWORD"] = "123456"
    
    mail = Mail(app)
    
    @app.route("/send_mail")
    def send_mail():
        """
        发送邮件
        """
        msg = Message(subject="Hello World!",sender="@163.com",recipients=["@qq.com"])
        msg.html = '<h1>hello world!</h1>'
        mail.send(msg)
        try:
            mail.send(msg)
        except Exception, e:
            traceback.print_exc()
            return "send error" + str(e)
        finally:
            return "Sent successfully"
    
    @app.route("/")
    def base():
       return render_template("product.html")
    
    
    if __name__ == "__main__":
        app.run(host='0.0.0.0',port=5000,threaded=True)
    
    一边喊着救命,一边享受沉沦。
  • 相关阅读:
    C#反射
    做下一周计划
    OFFSET 函数
    微信跳一跳学习笔记
    跳一跳脚本代码搬运
    预测羽毛球赛成绩学习笔记
    将Python123中作业成绩绘制成雷达图
    Matplotlib库
    Numpy库
    第四周作业
  • 原文地址:https://www.cnblogs.com/fast-walking/p/8930866.html
Copyright © 2011-2022 走看看