Python smtplib.SMTP connection failing

40 views Asked by At

I am trying to send an email and this code works on another box but it will not work on this one. I am assuming that it is firewall related but I do not know how to resolve it.


    server = smtplib.SMTP(timeout=15)
    print("defined server")
    server.connect("smtp.gmail.com", 587)
    print("Connected")
    server.ehlo()
    server.starttls()
    server.ehlo()
    print("starttls")
    server.login(username, password)
    print("login")
    server.sendmail(username, vtext, message)
    print("sendmail")
    server.quit()

I opened port 587 and telnet smtp.gmail.com 587 works.

Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\pcunningham\Anaconda3\lib\smtplib.py", line 398, in getreply line = self.file.readline(_MAXLINE + 1) File "C:\Users\pcunningham\Anaconda3\lib\socket.py", line 704, in readinto return self._sock.recv_into(b) socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\pcunningham\Anaconda3\lib\tkinter_init_.py", line 1892, in call return self.func(*args) File "c:\Users\pcunningham\Desktop\Email\Form.py", line 78, in send_text server.connect("smtp.gmail.com", 587) File "C:\Users\pcunningham\Anaconda3\lib\smtplib.py", line 343, in connect (code, msg) = self.getreply() File "C:\Users\pcunningham\Anaconda3\lib\smtplib.py", line 401, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed: " smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out

0

There are 0 answers