python - flask-mail 发送邮箱502错误
PHPz
PHPz 2017-04-17 17:35:15
0
3
905

贴出部分代码:

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

PHPz
PHPz

学习是最好的投资!

reply all(3)
巴扎黑

The following is an example of sending an email


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)
伊谢尔伦

You don’t have to SSL试试,或者用TLSChange the port to 25 and try again

大家讲道理

Set the port number to 25 and try it. In addition, the port number should be a number

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!