我正在使用带有ssl的flask + socketio,我正在尝试发送邮件,但由于某种原因,发送邮件不起作用。
这是我的配置:
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)
...
当我使用它时:
@app.route('/testMail')
def testMail():
msg = Message(
'Hello',
sender='xxx@gmail.com',
recipients=['xxx@gmail.com'])
msg.body = "This is the email body"
mail.send(msg)
return ""
这是错误日志:
文件“/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第 307 行,刷新 self._sock.sendall(view[write_offset :write_offset+buffer_size]) 文件“/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py”,第 721 行,在 sendall v = self .send(data[count:]) 文件“/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py”,第 687 行,在发送中 v = self._sslobj.write(data) 错误:[Errno 32] 管道损坏
...
文件“/usr/local/lib/python2.7/site-packages/flask_mail.py”,第 156 行,在 configure_host host = smtplib.SMTP_SSL(self.mail.server, self.mail.port) 文件“/usr/ local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py”,第 796 行,在init SMTP 中。初始化(自我,主机,端口,local_hostname,超时)文件“/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py”,第256行, 在初始化 (代码,味精)= self.connect(主机,端口)文件“/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py”,第 316 行,在 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”,第 801 行,在 _get_socket new_socket = socket.create_connection((host, port), timeout) 文件“/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/socket.py",第 575 行,在 create_connection 中 引发 err 错误:[Errno 65] 没有到主机的路由
由于某种原因,我无法发送任何电子邮件。由于 socketio + ssl 包装,它似乎卡住了。我不知道如何配置正确的方式。