首页 > 解决方案 > 电子邮件不显示超过 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 张图片没有显示。我试图改变图像的类型,但它不起作用。我想找出问题并解决它。

标签: pythonhtmlemail

解决方案


我通过将代码 msgImage.add_header('Content-ID','image%s'%i) 更改为 ''%i 解决了这个问题我认为问题是添加的图像的标题。


推荐阅读