Я получаю ConnectionResetError в приведенном ниже коде - PullRequest
0 голосов
/ 04 января 2019

в приведенном ниже коде я получаю сообщение об ошибке в server.starttls (), не могу найти решение. Я даже разрешил доступ к менее безопасному .... в моей учетной записи Google.

код:

   from getpass import getpass 
   import smtplib 

   server = smtplib.SMTP('smtp.gmail.com',587) 
   server.ehlo()

   server.starttls()

   username = input("Enter your Mail ID : ")

   server.login(username,getpass()) 

   toaddr = input("Enter Receiver Mail ID : ")
   message = input("Enter the Message : ")

   server.sendmail(username, toaddr, message)

   print('Message Sent')
   server.quit()

ошибка:

Traceback (most recent call last):``
  File "C:\Program Files\Python37\lib\smtplib.py", line 387, in getreply
    line = self.file.readline(_MAXLINE + 1)
  File "C:\Program Files\Python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\DELL\Documents\Python\Projects\Gmail.py", line 7, in <module>
    server.starttls()
  File "C:\Program Files\Python37\lib\smtplib.py", line 753, in starttls
    (resp, reply) = self.docmd("STARTTLS")
  File "C:\Program Files\Python37\lib\smtplib.py", line 421, in docmd
    return self.getreply()
  File "C:\Program Files\Python37\lib\smtplib.py", line 391, in getreply
    + str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [WinError 10054] An existing connection was forcibly closed by the remote host
...