使用sendgrid 邮件服务器报错,
配置如下:
MAIL_SERVER = os.getenv(“MAIL_SERVER”)
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = os.getenv(“MAIL_USERNAME”)
MAIL_PASSWORD = os.getenv(“MAIL_PASSWORD”)
MAIL_DEFAULT_SENDER = (“Lin”, MAIL_USERNAME)
.env文件
MAIL_SERVER=smtp.sendgrid.net
MAIL_USERNAME=bot@example.com
MAIL_PASSWORD=SG.klPkIDnATVCiKkFoE71x4g…
错误如下:
127.0.0.1 - - [06/Dec/2019 23:37:33] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [06/Dec/2019 23:37:35] "GET /technique/post/143 HTTP/1.1" 200 -
127.0.0.1 - - [06/Dec/2019 23:37:45] "POST /technique/post/143 HTTP/1.1" 302 -
127.0.0.1 - - [06/Dec/2019 23:37:45] "GET /technique/post/143 HTTP/1.1" 200 -
send: 'ehlo [10.198.75.60]\r\n'
reply: b'250-smtp.sendgrid.net\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-SIZE 31457280\r\n'
reply: b'250-AUTH PLAIN LOGIN\r\n'
reply: b'250 AUTH=PLAIN LOGIN\r\n'
reply: retcode (250); Msg: b'smtp.sendgrid.net\n8BITMIME\nPIPELINING\nSIZE 31457280\nAUTH PLAIN LOGIN\nAUTH=PLAIN LOGIN'
send: 'AUTH PLAIN AGJvdEBleGFtcGxlLmNvbQBTRy5rbFBrSURuQVRWQ2lLa0ZvRTcxeDRnLl95UWxZWjF0ZHpzRzZqQjJYWkh1WXNWaURrOVVyVmVVRVducy01UWxTUEE=\r\n'
reply: b'535 Authentication failed: Bad username / password\r\n'
reply: retcode (535); Msg: b'Authentication failed: Bad username / password'
send: 'AUTH LOGIN Ym90QGV4YW1wbGUuY29t\r\n'
Exception in thread Thread-12:
Traceback (most recent call last):
File "D:\soft\Python3.7.0\Lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "D:\soft\Python3.7.0\Lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "E:\my_project\PersonalBlog\PersonalBlog\emails.py", line 14, in _send_async_mail
mail.send(message)
File "e:\my_project\personalblog\pipenv_venv\personalblog-x-jrgtqq\lib\site-packages\flask_mail.py", line 491, in send
with self.connect() as connection:
File "e:\my_project\personalblog\pipenv_venv\personalblog-x-jrgtqq\lib\site-packages\flask_mail.py", line 144, in __enter__
self.host = self.configure_host()
File "e:\my_project\personalblog\pipenv_venv\personalblog-x-jrgtqq\lib\site-packages\flask_mail.py", line 165, in configure_host
host.login(self.mail.username, self.mail.password)
File "D:\soft\Python3.7.0\Lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "D:\soft\Python3.7.0\Lib\smtplib.py", line 631, in auth
(code, resp) = self.docmd("AUTH", mechanism + " " + response)
File "D:\soft\Python3.7.0\Lib\smtplib.py", line 421, in docmd
return self.getreply()
File "D:\soft\Python3.7.0\Lib\smtplib.py", line 394, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed