【问题标题】:Generate email with inline image使用内嵌图像生成电子邮件
【发布时间】:2013-03-14 22:21:05
【问题描述】:

我正在尝试生成其中插入图像的电子邮件文本。我知道我应该使用语法<img src="cid:image-id" /> 并将图像添加为附件。我尝试这样做,结果如下:

--===============6239034322813840804==
Content-Type: multipart/alternative;
 boundary="===============6051774682785554910=="
MIME-Version: 1.0

--===============6051774682785554910==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

my email in base64 with text only

--===============6051774682785554910==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

my email in base64 with html
...
<img src="cid:my-image.png" alt="My Image">
...

--===============6051774682785554910==--
--===============6239034322813840804==
MIME-Version: 1.0
Content-Type: image/png; name="badge-img.png"
Content-Disposition: inline; filename="badge-img.png"
Content-ID: <badge-img.png>
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
...

发送时,图片在附件中(可以打开,有效图片)。但在显示的电子邮件内容中,我只看到替代文本“我的图片”,而不是图片。

知道为什么吗?

【问题讨论】:

    标签: image email email-attachments


    【解决方案1】:

    您使用的是什么语言?在 C# 中,您需要尝试类似的方法:

    sending mail along with embedded image using asp.net

    Attaching Image in the body of mail in C#

    【讨论】:

    • 谢谢,但我认为这与编程语言(我使用 python)无关,而是与生成的电子邮件结构有关。
    • 好的,但是没有代码我们无法看到结构是如何创建的。
    【解决方案2】:

    好的,我想我找到了问题所在。我必须使用multipart/related 内容类型并更改结构。我目前有这样的东西

    <email>
        <part1 content-type=multipart/alternative>
            <subpart1>plain text</subpart1>
            <subpart2>html text</subpart2>
        </part1>
        <part2>
            attachments
        </part2>
    </email>
    

    应该有类似的东西

    <email>
        <part content-type=multipart/alternative>
            <subpart1>plain text</subpart1>
            <subpart2 content-type=multipart/related>
                <subsubpart1>html text</subsubpart1>
                <subsubpart2>attachments</subsubpart2>
            </subpart2>
        </part>
    </email>
    

    我仍然需要更改我的代码以适应,但这似乎是问题所在。

    【讨论】:

      猜你喜欢
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 2016-05-29
      相关资源
      最近更新 更多