学习进度:flask实战以看到电子邮件发送一章
遇见的问题:发送qq邮件失败 --未解决
贴上源码:希望有知道问题的指教一二
1 from flask import Flask, request
2 from flask_script import Manager,Shell
3 from flask_mail import Mail,Message
4 from threading import Thread
5 import os
6
7 app = Flask(__name__)
8
9 app.config['DEBUG'] = True
10
11
12 app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
13 app.config['MAIL_PORT'] = 465
14 app.config['MAIL_USE_SSL'] = True
15 app.config['MAIL_USE_TLS'] = False
16 app.config['MAIL_USERNAME'] = '1274802424@qq.com'
17 app.config['MAIL_PASSWORD'] = '**** **** **** ****'
18
19 manager = Manager(app)
20 mail = Mail(app)
21
22 def send_async_email(app,msg):
23 with app.app_context():
24 mail.send(msg)
25
26 @app.route('/')
27 def index():
28 msg = Message(subject='Email test by flask-email',sender="1274802424@qq. com",recipients=['1274802424@qq.com','1623721447@qq.com'])
29 msg.body = 'hello fulei'
30 msg.html = '<b>test for Flask mail send</b>'
31 thread = Thread(target=send_async_email,args=[app,msg])
32 thread.start()
33 return '<h1>send success</h1>'
34
35 if __name__ == '__main__':
36 manager.run()