python - 电子邮件不显示超过 9 张图片
问题描述
我想用python自动发送邮件,代码如下:
电子邮件的内容如下所示:
<table border="2">
<tr><th>Mx</th>
<th coslanb="5"> < img src="cid:image1" alt="image1" width="600" height="300" />< img src="cid:image2" alt="image2" width="500" height="300" /></th></tr>
<tr><th>Tger</th>
<th coslanb="5"> < img src="cid:image3" alt="image3" width="600" height="300" />< img src="cid:image4" alt="image4" width="500" height="300" /></th></tr>
<tr><th>1912</th>
<th coslanb="5"> < img src="cid:image5" alt="image5" width="600" height="300" />< img src="cid:image6" alt="image6" width="500" height="300" /></th></tr>
<tr><th>Gold</th>
<th coslanb="5"> < img src="cid:image7" alt="image7" width="600" height="300" />< img src="cid:image8" alt="image8" width="500" height="300" /></th></tr>
<tr><th>Abnormal</th>
<th coslanb="5">< img src="cid:image9" alt="image9" width="300" height="400" /> < img src="cid:image10" alt="image10" width="800" height="400" /></th></tr>
然后我对此进行编码以将图像添加到我的电子邮件中。
Files = [path1,...,path10]
i = 1
for filepath in Files:
f = open(filepath,'rb')
msgImage = MIMEImage(f.read())
f.close()
msgImage.add_header('Content-ID','image%s'%i)
msg.attach(msgImage)
i = i +1
最后,我发现第 10 张图片没有显示。我试图改变图像的类型,但它不起作用。我想找出问题并解决它。
解决方案
我通过将代码 msgImage.add_header('Content-ID','image%s'%i) 更改为 ''%i 解决了这个问题我认为问题是添加的图像的标题。
推荐阅读
- mysql - Proxysql 不会将数据发送到多数据库集群中的 MySQL 副本/从属服务器
- java - 如何从 crontab -e 触发 java 函数或类
- assembly - 结束 MIPS 汇编语言程序是否需要“jr $ra”?(MARS 和 QtSpim 的行为不同!)
- android - 将多个帐户所有者添加到单个 Google Play 开发者帐户
- laravel - 如何修复 Laravel 中的错误 npm “这与 npm 无法找到文件有关”?
- python - Pandas 从二维数组的字典中创建数据框
- javascript - 是否需要用“min”命名最小化文件?
- functional-programming - Java Lambda 函数接口提取到常用方法
- twitter - Headless Chrome 不执行 JS
- python - Python中的排序函数未返回预期结果