Flask 邮件应用程序中使用的应用程序配置(遵循 Miguel Grinberg Flask developlemt 书):
app.config['MAIL_SERVER'] = 'smtp.googlemail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')
邮件用户名和密码变量已正确设置并重新检查。在尝试使用以下代码发送消息时,
from flask.ext.mail import Message
from hello import mail
msg = Message('test subject', sender='same as MAIL_USERNAME', recipients=['check@mail.com'])
msg.body = 'text body'
msg.html = '<b>HTML</b> body'
with app.app_context():
mail.send(msg)
在发送时,应用程序一次又一次地导致以下错误:
SMTPSenderRefused: (530, '5.5.1 Authentication Required. Learn more at\n5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qb10sm6828974pbb.9 - gsmtp', u'configured MAIL_USERNAME')
该错误有任何解决方法吗?
最佳答案
在深入研究所面临的问题时,我重新检查了 Google 的 SMTP 设置,
改变
app.config['MAIL_SERVER'] = 'smtp.googlemail.com'
到
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
成功了。
还要确保完整用户名用作Gmail SMTP 用户名,即example@gmail.com 如上图所示。
希望这有帮助!!!
关于python - 从 Flask-Mail 发送邮件(SMTPSenderRefused 530),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28209414/