Output:
D:\Python\python3.exe "D:/PyCharm files/face/raspberry/smtp.py"
Traceback (most recent call last):
File "D:/PyCharm files/face/raspberry/smtp.py", line 43, in <module>
smtp.login( username, password ) #Login Server
File "D:\Python\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "D:\Python\lib\smtplib.py", line 631, in auth
(code, resp) = self.docmd("AUTH", mechanism + " " + response)
File "D:\Python\lib\smtplib.py", line 421, in docmd
return self.getreply()
File "D:\Python\lib\smtplib.py", line 394, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Solution:
Add two lines of code in front of SMTP. Login (user name, password) to send the mail successfully. The code added is as follows:
smtp.ehlo()
smtp.starttls()
The above solution can be solved in win server, but not in Linux server
Secure mail needs to be sent through SSL
server = smtplib.SMTP()
server.connect(email_host,25)
Exception thrown:
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
QQ mailbox supports secure e-mail and needs to send e-mail through SSL: when using the standard 25 port to connect to the SMTP server, it uses plaintext transmission, and the whole process of sending e-mail may be eavesdropped. To send e-mail more safely, you can encrypt the SMTP session, which is to create a SSL secure connection first, and then use the SMTP protocol to send e-mail
Modification code:
server = smtplib.SMTP_SSL()
server.connect(email_host,465)# Enable SSL messaging, port is usually 465
Similar Posts:
- [Solved] Python Error: CentOS failed to send mail without any error message
- Python Send Email Error: smtplib.SMTPException: SMTP AUTH extension not supported by server
- [Solved] smtplib Sent Email Error: SMTPDataError: (554, ‘DT:SPM 163 smtp1
- Error: need RCPT command
- Phpmailer’s solution to extension missing: OpenSSL error
- JavaMail uses 163 mailbox to report 535 error: authentication failed
- [mailbox usage] POP3, SMTP activation and setting method of Yahoo mailbox
- How to Solve Name Error: module ‘yagmail’ has no attribute ‘SMTP’
- Error reported when Foxmail software adds QQ email
- javax.net.ssl.SSLHandshakeException: No appropriate protocol [How to Solve]