实现步骤
设置邮件为多文本格式
1MIMEMultipart('related')编写html格式内容包含图片信息
12msgHtmlImg = '<img src="cid:image{count}"><br>'MIMEText(msgHtmlImg, 'html')读取图片并添加邮件头
1234567fp = open(imgpath, 'rb')msgImage = MIMEImage(fp.read())fp.close()# Define the image's ID as referenced abovemsgImage.add_header('Content-ID', '<image{count}>'.format(count=i))msgRoot.attach(msgImage)
完整发送邮件lib源码
|
|