Flask邮件应用程序中使用的应用配置(遵循Miguel Grinberg Flask开发书):
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')
有没有解决这个错误的方法?
source ~/.bash_profile
使我的工作正常,这会重新加载它。 - ss_millionaire