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.
The error is as follows:
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.
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:
The third step is to comment out the line that sets Content-Type in the original code and execute it successfully.
This problem puzzled me all afternoon, and I finally found out the cause based on the sent content and solved it.