""" author:少校 create Time:2025/2/24 11:25 越努力越幸运 """ from email.mime.image import MIMEImage from smtplib import SMTP_SSL from email.mime.multipart import MIMEMultipart #邮件类 from email.header import Header #邮件主题 from email.mime.text import MIMEText #正文类 connect = SMTP_SSL("smtp.qq.com","465") connect.login("85444652@qq.com","eueysxwzzfncbhab") mail = MIMEMultipart() mail["subject"] = Header("插入图片","utf-8").encode() mail["to"] = "99928838@qq.com" mail["from"] = "shaoxiao<85444652@qq.com>" #=======================图片内容=========================== #1.打开图片文件 image_data1 = open("files/自动化办公.png","rb").read() #2.创建图片对象 img1 = MIMEImage(image_data1) #3.给图片对象添加ID img1.add_header("Content-ID","<i1>") #4.将图片对象关联到邮件中 mail.attach(img1) #5.在正文中使用图片 #<img src="cid:i1"> text = MIMEText('图1:<br><img src="cid:i1">',"html","utf-8") mail.attach(text) # connect.sendmail("85444652@qq.com","99928838@qq.com",mail.as_string()) connect.quit()
03.邮件插入图片
本节944字2025-02-24 17:33:46