#!/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)