因此,SMTPSenderRefused
当我尝试使用我构建的烧瓶应用程序发送电子邮件时出现错误。让我开始购买,说这以前有效,但现在已经停止了。我不知所措,我花了很多时间在网上进行测试、调整和阅读,但没有什么能给我答案。
我不断收到以下错误。
[2019-01-21 03:07:51,954] ERROR in app: Exception on /register/ [POST]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "MyFlaskApp.py", line 131, in register
mail.send(msg)
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 492, in send
message.send(connection)
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 427, in send
connection.send(self)
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 192, in send
message.rcpt_options)
File "/usr/lib64/python2.7/smtplib.py", line 737, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (530, '5.5.1 Authentication Required. Learn more at\n5.5.1 https://support.google.com/mail/?p=WantAuthError u186sm20332024pfu.51 - gsmtp', u'myemail@gmail.com')
IP.XX.XXX.XXX - - [21/Jan/2019 03:07:51] "POST /register/ HTTP/1.1" 500 -
我的 gmail 帐户配置了两步验证,然后是这个 Flask 应用程序使用的应用程序密码。我已经尝试了所有组合,但仍然无法正常工作。这是我正在使用的代码。
app = Flask(__name__, static_url_path='/static')
app.config.update(
DEBUG = False,
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 465,
MAIL_USE_SSL = True,
MAIL_USERNAME = 'myemail@gmail.com',
MAIL_DEFAULT_SENDER = 'myemail@gmail.com',
MAIL_PASSWORD = 'GmailApplicationPassword',
)
mail = Mail(app)
实际发送消息的行(在 POST 内):
msg = Message("Welcome",
sender = 'myemail@gmail.com',
recipients = [request.form["email"]])
msg.body = "Welcome! \n\n Congratulations on your successful registration. \n\n Cheers!"
mail.send(msg)
一些可能有用的附加信息。当我在本地运行我的应用程序时,这个确切的代码曾经可以工作。然后我将我的代码部署到我的 AWS EC2 实例并让它在那里运行。在我执行以下操作之前,它一直在工作。
我将一个弹性 IP 地址与该站点相关联,然后将我的 DNS 指向该 IPv4。我还添加了 AWS 公共证书。
有人可以帮我理解为什么我无法发送电子邮件。我已经尝试了所有可以在网上找到的解决方案。
额外细节:
$ pip freeze
Flask-Mail==0.9.1
在此先感谢,如果需要更多说明,我将帮助提供任何答案,因此请询问。