python - flask-mail如何配置QQ邮箱?
伊谢尔伦
伊谢尔伦 2017-04-17 17:26:11
0
1
689

app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')

在环境中配置(所在平台为windows,假设我邮箱为6666@qq.com, 密码也为6666):

set MAIL_USERNAME = 6666 #only an example, int type
set MAIL_PASSWORD = 6666 #int type

然后进入python的shell输入

from flask.ext.mail import Message
from hello import mail #hello就是我的model(.py文件)
msg = Message('subject', sender='6666@qq.com', recipients=['6666@qq.com'])
msg.body = 'body content'
msg.html = '<h1>Why it doesn't work?</h1> body'
with app.app_context():

mail.send(msg)

运行后一直无反应,没结果出现。将mail_server换成mx1.qq.com后直接出现TimeoutError,10060

感觉应该是qq邮箱的配置方面出错,但具体找不出在哪里。求教原因,谢谢!

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

répondre à tous(1)
黄舟

你应该先到QQ邮箱里面开启smtp服务。操作过程为【QQ邮箱首页】->【设置】->【账户】->【POP3/SMTP服务】,按提示把这个服务开启后,你会得到一串码,记住这串码。然后配置的时候username为你的QQ邮箱账户,密码填上刚才那串码即可。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!