尝试使用烧瓶发送电子邮件时发生错误

时间:2019-02-14 21:13:44

标签: python flask

我一直在尝试使用烧瓶发送电子邮件,但我一直收到错误消息

  

smtplib.SMTPServerDisconnected:请先运行connect()

代码如下:

    app.config["DEBUG"] = True
    app.config["TESTING"] = False
    app.config["MAIL_SERVER"] = 'smtp.gmail.com'
    app.config["MAIL_PORT"] = 587
    app.config["MAIL_USE_SSL"] = False
    app.config["MAIL_USE_TLS"] = True
    app.config["MAIL_USERNAME"] = 'mattpythonapp@gmail.com'
    app.config["MAIL_PASSWORD"] = 'password'
    app.config["MAIL_DEFAULT_SENDER"] = 'mattpythonapp@gmail.com'
    app.config["SECURITY_EMAIL_SENDER"] = 'mattpythonapp@gmail.com'
    mail.init_app(app)

@app.route('/contact', methods=['GET', 'POST'])
def contact2():
    msg = Message('Hey There', recipients=['mattpythonapp@yahoo.com'])
    mail.send(msg)

0 个答案:

没有答案
相关问题