我想在我的网络应用程序中使用烧瓶邮件,我得知错误,我不太懂。遵循指南并且无法使其发挥作用。在以下过程中,我希望应用程序向新注册用户发送电子邮件。
配置:
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
有什么想法吗?
答案 0 :(得分:9)
config 文件中的设置似乎有一个尾随逗号,这会使它们成为元组。 Flask-Mail抱怨传入getaddrinfo的host
值不是字符串 - 它很可能是一个元组。
删除尾随逗号可能会解决此问题。