python - 身份验证出错时,烧瓶邮件引发异常
问题描述
首先,我要感谢大家。
我有一个关于烧瓶邮件的快速问题。
我想在发送电子邮件时遇到异常或捕获错误。
from flask import Flask, request
from flask_mail import Mail, Message
import os, sys
app = Flask(__name__)
mail= Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_DEBUG'] = True
app.config['MAIL_USERNAME'] = 'xyz@gmail.com'
app.config['MAIL_PASSWORD'] = 'njhkjkjj'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
@app.route('/email')
def get_email():
if mail.connect() == None:
print("Email setup/password is incorrect. Input your email creadentials in python app..")
else:
msg = Message('visitor blocked', sender = 'abc@gmail.com', recipients = ['xyz@gmail.com'])
msg.body = "Hello, this is email test."
mail.send(msg)
print("Email setup is ready. Email is sent..")
我试图得到一个错误,并在密码不正确的地方使用上面的块代码引发错误消息。但它最终有一个例外。
smtplib.SMTPAuthenticationError
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials o23sm485224lfr.302 - gsmtp')
任何关于可以改进的帮助或建议都会有所帮助。谢谢你。
解决方案
推荐阅读
- symfony4 - Fosrestbundle 表单错误 value is not valid entitytype
- reactjs - 反应将两个参数函数传递给 onContextMenu 事件
- ios - 应用内购买iOS:沙盒环境中不调用Transaction State .purchased
- javascript - 节点路径在 Linux 和 windows 上输出不同的值
- twitter-bootstrap - Bootstrap 4.xx 版,弹出器更改下拉位置时自动方向插入符号
- sql - SQL Group by query with case 语句问题
- java - 如何创建具有平均深度的文件夹和子文件夹
- keras - 如何在 keras 的自定义损失函数中调用预训练的解码器模型?
- java - 从 infinity RecyclerView 获取项目值
- python - 如何对 python 字典进行数学运算?