我想在我的 web 应用程序中使用烧瓶邮件,但我遇到了我不太了解的错误。一直遵循指导方针,但无法让它发挥作用。在以下过程中,我希望应用程序向新注册用户发送电子邮件。
配置:
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USE_TLS=False,
MAIL_USERNAME = 'myMail@gmail.com',
MAIL_PASSWORD = '******'
看法:
from flask_mail import Mail, Message
mail = Mail(app)
@app.route("/send_mail/")
def send_mail():
msg = Message('Hello', sender = 'myMail@gmail.com', recipients = ['somebody@gmail.com'])
msg.body = "This is the email body"
mail.send(msg)
我得到的错误:
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1994, in __call__
return self.wsgi_app(environ, start_response)
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\venvs\test\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\venvs\test\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\venvs\test\views.py", line 202, in send_mail
mail.send(msg)
File "C:\venvs\test\lib\site-packages\flask_mail.py", line 491, in send
with self.connect() as connection:
File "C:\venvs\test\lib\site-packages\flask_mail.py", line 144, in __enter__
self.host = self.configure_host()
File "C:\venvs\test\lib\site-packages\flask_mail.py", line 156, in configure_host
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
File "C:\Python\lib\smtplib.py", line 1029, in __init__
source_address)
File "C:\Python\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python\lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python\lib\smtplib.py", line 1035, in _get_socket
self.source_address)
File "C:\Python\lib\socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Python\lib\socket.py", line 743, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
TypeError: getaddrinfo() argument 1 must be string or None
有任何想法吗?