I'm using flask + socketio with ssl, and I'm trying to send mail, but for some reason, sending mail is not working.
Here is my configuration:
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'xxx;'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
app.config['DEBUG'] = True
mail=Mail(app)
...
And when I'm using it:
@app.route('/testMail')
def testMail():
msg = Message(
'Hello',
sender='[email protected]',
recipients=['[email protected]'])
msg.body = "This is the email body"
mail.send(msg)
return ""
And here is the error log:
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 307, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 721, in sendall v = self.send(data[count:]) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 687, in send v = self._sslobj.write(data) error: [Errno 32] Broken pipe
...
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 156, in configure_host host = smtplib.SMTP_SSL(self.mail.server, self.mail.port) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 796, in init SMTP.init(self, host, port, local_hostname, timeout) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 256, in init (code, msg) = self.connect(host, port) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 316, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 801, in _get_socket new_socket = socket.create_connection((host, port), timeout) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection raise err error: [Errno 65] No route to host
For some reason, I can't send any email. It seems stuck because of the socketio + ssl wrapping. I've got no idea on how to configure the right way.
No route to host
in the error log. Check the network connection to the server and port from your program. It may be prohibited by a firewall. – VPfB