在Python官网上看到这个例子
import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart()
msg['Subject'] = 'subjest'
msg['From'] = "******@qq.com"
msg['To'] = "*****@qq.com"
body = MIMEText("中国人不是东亚病夫") #正文
with open('test.png', 'rb') as fp: #附件
img = MIMEImage(fp.read())
msg.attach(img)
msg.attach(body)
s = smtplib.SMTP('smtp.qq.com')
s.login("*******@qq.com", "****password*****")
s.send_message(msg)
s.quit()
几行就解决了mime类型和邮件的编码问题,还能发送附件
唯一问题是附件的扩展名从png变成了bin.windows下要改一改,一口气解决了前几天用c++编用的smtp指令的全部问题,