2016-07-12 8 views
0

Ich benutze Kolben + socketio mit ssl, und ich versuche, Mail zu senden, aber aus irgendeinem Grund funktioniert das Senden von E-Mails nicht.flask_mail, Mails sind auf Thread fest und werden nie gesendet

Hier ist meine Konfiguration:

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) 

...

Und wenn ich verwende es:

@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 "" 

Und hier das Fehlerprotokoll:

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

Aus irgendwelchen Gründen kann ich keine senden Email. Es scheint wegen der socketio + ssl Wrapping fest. Also habe ich keine Ahnung, bekam wie man die richtige Art und Weise konfigurieren

+0

Es gibt keine Route zum Host im Fehlerprotokoll. Überprüfen Sie die Netzwerkverbindung zum Server und Port von Ihrem Programm. Dies kann durch eine Firewall verhindert werden. – VPfB

Antwort

0

ich hatte das gleiche Problem, wenn Ihr in einer virtuellen Maschine arbeiten für den ssh Port der Netzwerkverbindung überprüfen, in meinem Fall habe ich mit vagrant arbeiten, ich fähigen Anschluss für den ssh Port funktioniert dieser Code zu mir:

from flask import Flask 
from flask_mail import Mail, Message 

# object Flask and object Mail 

app = Flask(__name__) 
#configuration flask to Mail 
app.config.update(
      MAIL_SERVER = "smtp.gmail.com", 
      MAIL_PORT = 465, 
      MAIL_USERNAME = '[email protected]', #user mail 
      MAIL_PASSWORD = 'xxx', 
      MAIL_USE_TLS = False, 
      MAIL_USE_SSL = True, 
      MAIL_DEFAULT_SENDER = '[email protected]', #user that will go email) 
mail = Mail(app) 

@app.route("/index") 
def index(): 
    return "ok" 


@app.route("/Test Mail") 
def test_mail(): 
    """route to test email by flask mail.""" 
    msj = "This is a test to send mail with flask." 
    recipients = ["[email protected]"] 
    msg_object = Message("hello", recipients) 
    msg_object.body = "Hello, this email is a test" 
    mail.send(msg_object) 
    return "Sent" 



if __name__ == '__main__': 
    app.run(host="0.0.0.0", port=7000, debug=True) 

Außerdem sollten Sie überprüfen, ob die eingebaute Unsicherheit kennzeichnet in Gmail service kann diesen Anmeldeversuch blockieren. Melden Sie sich in Ihrem Konto an und besuchen Sie .

Verwandte Themen