im 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