1 from flask_mail import Mail,Message 2 from flask import Flask 3 import os 4 5 app=Flask(__name__) 6 app.config.update( 7 DEBUG = True, 8 MAIL_SERVER='smtp.qq.com', 9 MAIL_PROT=25, 10 MAIL_USE_TLS = True, 11 MAIL_USE_SSL = False, 12 MAIL_USERNAME = '4@qq.com', 13 MAIL_PASSWORD = 'xxxxxxxx', 14 #MAIL_PASSWORD = 'xxxxxxxx', 15 MAIL_DEBUG = True 16 ) 17 mail=Mail(app) 18 19 20 @app.route('/') 21 def index(): 22 # sender 發送方哈,recipients 郵件接收方列表 23 msg = Message("Hi!This is a test ",sender='4@qq.com', recipients=['3@qq.com']) 24 # msg.body 郵件正文 25 msg.body = "This is a first email" 26 # msg.attach 郵件附件添加 27 # msg.attach("文件名", "類型", 讀取文件) 28 # with app.open_resource("F:\2281393651481.jpg") as fp: 29 # msg.attach("image.jpg", "image/jpg", fp.read()) 30 31 mail.send(msg) 32 print ("OK") 33 return "Sent" 34 35 36 37 38 if __name__=='__main__': 39 app.run(debug=True)
發送一直失敗,查網上比較靠譜的方法參考兩篇文章flask
http://blog.csdn.net/huochen1994/article/details/51282093app
http://tieba.baidu.com/p/3870714637 這個帖子的最後一答spa