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)
    
    一边喊着救命,一边享受沉沦。
  • 相关阅读:
    js使用笔记
    rabbit-mq使用官方文档
    tomcat Enabling JMX Remote
    Venom的简单使用
    Random模块
    时间模块
    shulti模块简述
    Python的os模块
    Python压缩及解压文件
    Kali的内网穿透
  • 原文地址:https://www.cnblogs.com/fast-walking/p/8930866.html
Copyright © 2011-2022 走看看