首页 > 解决方案 > 在多部分 html 电子邮件中嵌入图像 - 正确定义链接的图像

问题描述

我在多部分电子邮件中嵌入图像时遇到困难。

我正在尝试将包含大量嵌入图像的 html 文件作为邮件发送出去。但是,图像不会出现,目前只是作为附件发送。

我假设我无法链接 html 代码。这是第一张图片的部分 HTML 代码

     </v:shapetype><v:shape id="Picture_x0020_5" o:spid="_x0000_i1029" type="#_x0000_t75"
   alt="cid:image001.png@01D58F16.6A9DB2F0" style='width:441.45pt;height:183.85pt;
   visibility:visible;mso-wrap-style:square'>
   <v:imagedata src="somefolder-data/image001.png"
    o:title="image001.png@01D58F16"/>

图像不放置在工作目录本身中。

我认为问题在于定义上面在 HTML 中引用的图像 ID,这看起来与在线示例不同。我尝试了几个版本,但没有成功。

我假设 cid 后面的部分是相关的(所以 image001.png),但它可能是“image001.png@01D58F16.6A9DB2F0”。

有人可以帮助在这里建立正确的联系吗?

        msgImage = MIMEImage(fp.read())
        fp.close()

        msgImage.add_header('Content-Disposition', 'inline', filename='image001.png')

        # Attach part into message container.

        msg.attach(msgImage)




提前致谢

标签: pythonhtmlhtml-emailmultipart

解决方案


推荐阅读