我是Python的新手。我想发送带有多个嵌入图像的基于html的电子邮件
使用下面的代码,电子邮件是绝对有效的,但只能查看一个嵌入的图像和另一个未定义的图像
def addMultipleEmbeddedImages(self, nbMsg=1):
attachedFiles = ["giga_logo_300x225.png", "phone_logo.jpg"]
self.imgHtml = ""
for file1 in attachedFiles:
file = os.path.join(pathToAttachments, file1)
self.__msg = MIMEMultipart('related')
self.imgHtml +='<p <u>Embedded Images</u></p><br><img src="cid:%s"><br>'%file
self.__msg.attach(MIMEText(self.imgHtml, 'html'))
fp = open(file, 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header('Content-ID', '<%s>'%file)
self.__msg.attach(msgImage)
self.__fillInAddressFields()
# Attach the email in the body
self.__buildBody(self.__msg)
# Send the email with the embedded image
self.__sendMessages(nbMsg)
return
在这里,我为每个图像设置了名称
相关问题 更多 >
编程相关推荐