python - flask_mail, mails are stuck on thread and are never send -
i'm using flask + socketio ssl, , i'm trying send mail, reason, sending mail not working.
here configuration:
app.config['mail_server']='smtp.gmail.com' app.config['mail_port'] = 465 app.config['mail_username'] = 'xxx@gmail.com' 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='xxx@gmail.com', recipients=['xxx@gmail.com']) msg.body = "this email body" mail.send(msg) return ""
and here 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 host
for reasons, can't send email. seems stuck because of socketio + ssl wrapping. i've got no idea on how configure right way
i had same issue, if working in virtual machine check network connection ssh
port, in case work vagrant
, enabled connection ssh
port, code works me:
from flask import flask flask_mail import mail, message # object flask , object mail app = flask(__name__) #configuration flask mail app.config.update( mail_server = "smtp.gmail.com", mail_port = 465, mail_username = 'xxx@gmail.com', #user mail mail_password = 'xxx', mail_use_tls = false, mail_use_ssl = true, mail_default_sender = 'xxx@gmail.com', #user go email) mail = mail(app) @app.route("/index") def index(): return "ok" @app.route("/test mail") def test_mail(): """route test email flask mail.""" msj = "this test send mail flask." recipients = ["xxxemail@gmail.com"] msg_object = message("hello", recipients) msg_object.body = "hello, email test" mail.send(msg_object) return "sent" if __name__ == '__main__': app.run(host="0.0.0.0", port=7000, debug=true)
also, should verify if built-insecurity features in gmail service
may block login attempt. log in account , visit https://www.google.com/settings/security/lesssecureapps.
Comments
Post a Comment