if attachment.endswith(".jpg"):
fp = open(attachment, "rb")
file_msg = MIMEImage(fp.read())
fp.close()
file_msg.add_header("Content-ID", os.path.basename(attachment).replace(".jpg", ""))
main_msg.attach(file_msg)
else:
file_msg=email.MIMEBase.MIMEBase("application","octet-stream")
f=open(attachment,'rb')
file_msg.set_payload(f.read())
f.close()
email.Encoders.encode_base64(file_msg)
file_msg.add_header('Content-Disposition','attachment',filename=os.path.basename(attachment))
main_msg.attach(file_msg)
发送内嵌图片,需要使用<img src=\"cid:[basename]\"/>来嵌入