I want to use flask mail in my webapp and I am gettin error that I don't really understand. Been following guidelines and can't get it to work. In the following proccess I want app to send email to new registered user.
Config:
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USE_TLS=False,
MAIL_USERNAME = '[email protected]',
MAIL_PASSWORD = '******'
View:
from flask_mail import Mail, Message
mail = Mail(app)
@app.route("/send_mail/")
def send_mail():
msg = Message('Hello', sender = '[email protected]', recipients = ['[email protected]'])
msg.body = "This is the email body"
mail.send(msg)
Error I am getting:
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
Any ideas?
Your settings in your config file seem to have a trailing comma, which would make them tuples. Flask-Mail is complaining that the host
value passed in to getaddrinfo is not a string - it's most likely a tuple.
Removing the trailing commas may fix this issue.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments