python - flask-mail 发送邮箱502错误

查看:190
本文介绍了python - flask-mail 发送邮箱502错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

贴出部分代码:

app.config['MAIL_SERVER'] = 'smtp.163.com'
app.config['MAIL_PORT'] = '994'
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '我的手机@163.com'
app.config['MAIL_PASSWORD'] = '我的登录密码'

msg = Message('test', sender='我的手机@163.com', recipients=['xxxxxxx@qq.com'])
    msg.body = '文本 body'
    msg.html = '<b>HTML</b> body'
    with app.app_context():
        mail.send(mail)

运行后出现以下错误:

从上面错误看起来好像是send的错误,而且错误原因应该是没有实现的命令,但是这不是flask-mail的写法吗?smtp用的是网易邮箱,按照它所说的去配置,应该是没有问题才对的。。。

解决方案

以下是发送邮件例子


from flask import Flask
from flask.ext.mail import Mail, Message

app=Flask(__name__)

app.config.update(
    MAIL_USE_SSL= True,
    MAIL_USE_TLS=True,
    MAIL_SERVER='smtp.163.com',
    MAIL_PORT=465,
    MAIL_USERNAME='your_count@163.com',
    MAIL_PASSWORD='your_password'
)

mail=Mail(app)

@app.route("/")
def index():
    msg = Message(
        'Hello',
        sender='sender@163.com',
        recipients=
        ['receiver@qq.com'])
    msg.body = "This is the email body"
    mail.send(msg)
    return "Sent"

if __name__ == "__main__":
    app.run(port=8888)

这篇关于python - flask-mail 发送邮箱502错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆