在通过python smtplib发送电子邮件时向图像附件添加href链接

2024-04-24 23:09:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用smtplib将图像作为附件发送,并将它们作为email.mime.base.MIMEBase对象附加。这些图像显示在电子邮件正文中。我希望这些图片可以点击。是否可以向每个图像添加HREF?你知道吗

以下是附加图像的代码:

msg = MIMEMultipart()
msg['From'] = email_username
msg['To'] = ", ".join(destination_list)
msg['Subject'] = "Subject goes here"

message_body = "<b>Message body</b>"

msg.attach(MIMEText(message_body, 'html'))

part = MIMEBase('application', 'octet-stream')
part.set_payload(open('attachment.png','rb').read())
encoders.encode_base64(part)
part.add_header('Content-Disposition')
msg.attach(part)

Tags: 对象图像message附件base电子邮件emailbody