首页 > flask-mail 发送邮箱502错误

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用的是网易邮箱,按照它所说的去配置,应该是没有问题才对的。。。


把端口号设置为25试一试,另外端口号应该是个数字


你不用 SSL试试,或者用TLS把端口改成25在试试


以下是发送邮件例子


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)
【热门文章】
【热门文章】