Python series problem set 04-Python smtplib package function MIMEText stepped on the pit, sending emails with attachments has been stuck, close the connection after about 10 minutes, troubleshooting ideas

The daily operation and maintenance process uses the python2.7.15 version. After installing the smtplib package, test the email sending, including the text and attachments.

The first step is to follow https://www.runoob.com/python/python-email.html to introduce the email sending sample test.

Insert image description here

The error is as follows:
Insert image description here
So Baidu inquired about the cause of this problem, and found the following article
link: link
I thought it was only MIMEBase for sending attachments, so I adjusted it according to this method, and the execution was successful.
Insert image description here

The second step is to check the differences between MIMEBase and MIMEText.

Add smtpObj.set_debuglevel(1) to the script to print relevant log information and view the content sent, as shown below:
Insert image description here

The third step is to comment out the line that sets Content-Type in the original code and execute it successfully.

Insert image description here
This problem puzzled me all afternoon, and I finally found out the cause based on the sent content and solved it.

Summary: https://www.runoob.com/python/python-email.html The above example is not necessarily correct.

おすすめ

転載: blog.csdn.net/weixin_40012925/article/details/128257018