Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python脚本发送包含多个嵌入图像的html电子邮件_Python - Fatal编程技术网

使用python脚本发送包含多个嵌入图像的html电子邮件

使用python脚本发送包含多个嵌入图像的html电子邮件,python,Python,我是Python的新手。我想发送带有多个嵌入图像的基于html的电子邮件 使用下面的代码,电子邮件是绝对有效的,但只能查看一个嵌入的图像和另一个未定义的图像 def addMultipleEmbeddedImages(self, nbMsg=1): attachedFiles = ["giga_logo_300x225.png", "phone_logo.jpg"] self.imgHtml = "" for file1 in attache

我是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
def addmultiplembeddedimages(self,nbMsg=1):
附件文件=[“giga_logo_300x225.png”,“phone_logo.jpg”]
self.imgHtml=“”
对于附件文件中的文件1:
file=os.path.join(pathToAttachments,file1)
self.\uuu msg=MIMEMultipart('相关')
self.imgHtml+='

在这里,我为每个图像设置了名称。

我认为您在第一个元素中缺少了一个闭合角括号。并且。。您可能希望在循环之外生成html的第一部分,这样就不会在每个图像上方出现短语“嵌入图像”。
msgImage = MIMEImage(fp.read(),name = os.path.basename(file1))