python - 在多部分 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)
提前致谢
解决方案
推荐阅读
- gitlab - Sourcetree 现有 repo 没有分支,不能创建一个
- spring-boot - Spring Kafka Stream - 标头中没有类型信息,使用 BiFunction 时没有提供默认类型
- powershell - 在 bat 文件中以管理员身份运行 powershell 命令
- google-cloud-functions - 来自(AI 平台)的 ML 模型如何与云调度程序自动执行?
- react-native - react native modal 需要 2 秒才能打开
- c# - 为什么在合作取消中任务的状态是“故障”而不是“取消”?
- macos - macOS 路径搞砸了。“找不到相关命令”
- jquery - JQuery 3.6.0 过滤事件一无所获?
- python-3.x - 浏览器使用域名但不在本地服务器上超时
- r - 动态变异数据框列表中的列向量