import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
msg = MIMEMultipart('multipart/related')
fromaddr = 'from@gmail.com'
toaddrs = 'to@gmail.com'
#provide gmail user name and password
username = 'to@gmail.com'
password = 'messifan'
filename = "1.jpg"
f = file(filename)
attachment = MIMEImage(f.read()) # error here
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
.
.
server.sendmail(fromaddr, toaddrs, msg.as_string())
我正在使用此代码发送电子邮件。我可以使用此脚本附加文本文件。(将 MIMEImage 转换为 MIMEtext)。但无法附加图像。错误是无法猜测图像 mime 子类型