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)
    
    一边喊着救命,一边享受沉沦。
  • 相关阅读:
    Java: 数据类型
    数据结构是什么
    数据结构:进制转换
    数据结构:堆与栈
    class的写法
    Java:异常体系
    数据结构: 先进后出——堆栈
    tomcat:web容器
    Windows: Dos命令
    面向函数范式编程
  • 原文地址:https://www.cnblogs.com/fast-walking/p/8930866.html
Copyright © 2011-2022 走看看