Flask Web开发 电子邮件发送问题详解

按书上的内容结果报出服务器拒绝


于是换qq邮箱服务器,结果报如下错误:

smtplib.SMTPAuthenticationError:(535,b'Error:\xc7\xeb\xca\xb9\xd3\xc3\xca\xda\xc8\xa8\xc2\xeb\xb5\xc7\xc2\xbc\xa1\xa3\xcf\xea\xc7\xe9\xc7\xeb\xbf\xb4: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256')

原因在于邮箱密码不能直接输入自己的密码:

因此找到MAIL_PASSWORRD的正确值,以下是详细方法:


然后往下拉,找到下面的,点击开启,然后按步骤发送短信,会恢复一串字符,然后写入MAIL_PASSWORRD处。

以下是完整简短实例代码:

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)
app.config.update(
    DEBUG = True,
    MAIL_SERVER='smtp.qq.com',
    MAIL_PROT=25,
    MAIL_USE_TLS = True,
    MAIL_USE_SSL = False,
    MAIL_USERNAME = '2531412**4@qq.com',
    MAIL_PASSWORD = 'x**********if',
    MAIL_DEBUG = True
)
mail = Mail(app)

@app.route('/')
def index():
    msg = Message("test ",sender='2531412**4@qq.com', recipients=['187****7785@163.com'])#改成你自己的邮箱,并且第一处必须与上面配置的相同。
    msg.body = "This is a first email"
    msg.html = 'HTML body'
    with app.app_context():
        mail.send(msg)
    print("Mail sent successful!")
    return "Mail sent successful!"

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值