所以我构建了一个烧瓶应用程序,当我在本地运行它时效果很好。然后我将它推送到我的 AWS EC2 实例。一旦我从我的实例运行它,它就不再发送电子邮件。它会添加到我的数据库中,然后下一行是发送电子邮件。那就是它失败的地方。是谷歌阻止了该设备。然后我能够允许该设备并且一切正常。
快进,我添加了一个弹性 IP,然后将它链接到我的域,现在它不再工作了。它仍在添加到我的数据库中,所以我认为问题在于谷歌没有让应用程序工作。我不知道如何解决这个问题,但我已经为此工作了一段时间。这是我在我的实例上得到的错误代码
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 "FlaskApp.py", line 130, 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 178, in send
"The message does not specify a sender and a default sender "
AssertionError: The message does not specify a sender and a default sender has not been configured
在我的网站上,我看到“500 Internal Server Error”的标签,网站显示以下内容。
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
有人可以帮我解决这个问题。我希望能够使用我的烧瓶应用再次发送电子邮件。我是新手,所以我的逻辑说这完全是因为我被拒绝访问谷歌帐户。但是我找不到可以让我允许访问 EC2 实例的链接或任何内容。我什至尝试过使用它:https ://accounts.google.com/DisplayUnlockCaptcha但这也不起作用。
更新: 它之前工作过,我没有更改源代码中的任何内容,见下文:
FROM_EMAIL = os.environ.get('EMAIL_USERNAME')
app.config.update(
DEBUG = False,
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 465,
MAIL_USE_SSL = True,
MAIL_USERNAME = FROM_EMAIL,
MAIL_PASSWORD = os.environ.get('EMAIL_PASSWORD_TOKEN'),
)
mail = Mail(app)
然后当我打电话时我使用:
msg = Message("Welcome",
sender = FROM_EMAIL,
recipients = [request.form["email"]])
msg.body = "Welcome! \n\n Congratulations on your sucessful registration."
mail.send(msg)
更新#2: 我不知道为什么,但我必须添加一个默认发件人,这有效,但我仍然无法发送电子邮件。我现在收到以下错误:
[2019-01-22 01:40:44,973] 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 "FlaskApp.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 d21sm19653189pfo.162 - gsmtp', u'myemail@gmail.com')
199.169.1.69 - - [22/Jan/2019 01:40:44] "POST /register/ HTTP/1.1" 500 -
不知道知道是否有帮助,但我可以使用实例中的 SMTP cmds 登录 gmail,但我仍然收到错误消息。我按照此处的说明进行操作:如何通过 Gmail 使用简单的 SMTP 命令发送电子邮件?