带有嵌入式图像和zip附件的python html MIME电子邮件在Outlook中显示问题

时间:2019-06-13 16:11:40

标签: python email outlook mime-types email-attachments

我正在通过MIMEMultipart()在python 3.6中生成电子邮件。电子邮件通过HTML格式化,我正在嵌入图像并附加一个zip文件。如果仅嵌入图像,则该电子邮件在Outlook 365中看起来不错,并且可以正确看到该图像。如果我嵌入图像并附加了我的zip文件,则会同时获得两个附件(图像和zip),但是图像不会填充,而我只会获得图像的“ x”

我确实发现它在gmail中可以正确显示,但在图像和zip的情况下却不能在Outlook中显示。...

添加图像和zip的代码如下:

def attach_zip(self, zip_filename):
        """   Attach a zip file to the email

              :param zip_filename: string path to the zip file to attach
              :type zip_filename: str
        """
        with open(zip_filename, 'rb') as fp:
            mime = MIMEApplication(fp.read(), self.sub_type)
            mime.add_header('X-Attachment-Id', 'zip2')
            mime.add_header('Content-Disposition', 'attachment', filename=os.path.basename(zip_filename))
            mime.add_header('Content-ID', '<zip2>')
            mime.add_header('Content-Disposition', 'inline', filename=os.path.basename(zip_filename))
            self.msg.attach(mime)


def attach_picture(self, pic_filename):
        """   Attach a single picture to the email

              :param pic_filename: name of image to attach
              :type pic_filename: str
        """
        print('attaching image..{}'.format(pic_filename))
        with open(pic_filename, 'rb') as fp:
            img = MIMEImage(fp.read(), self.sub_type)
            img.add_header('X-Attachment-Id', 'image1')
            img.add_header('Content-ID', '<image1>')
            img.add_header('Content-Disposition', 'in-line', filename=pic_filename)
            self.msg.attach(img)

有什么想法吗?我觉得它是Outlook的内容标题问题吗?我已经尝试过Web Outlook和胖客户端,但得到的结果相同。

0 个答案:

没有答案