search

Home  >  Q&A  >  body text

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

PHPzPHPz2813 days ago956

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:37:15

    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)

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:37:15

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:37:15

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

    reply
    0
  • Cancelreply