【问题标题】:Embedded images (inline) within html body in email showing as attachment电子邮件中 ​​html 正文中的嵌入图像(内联)显示为附件
【发布时间】:2015-10-09 21:43:17
【问题描述】:

我已成功将图像(徽标)添加为 html 电子邮件消息中的内联。 但是,它还显示了下载此类图像作为附件的链接。在雅虎邮件附件中的所有可用图片

我的东西如下,

<html>
    <body>
        <img src="cid:mylogo.png" />
        <table>
            .
            .
            .
        </table>
    </body>
</html>

 Multipart multipart = new MimeMultipart();
 MimeBodyPart imagePart = new MimeBodyPart();
 DataSource ds = new FileDataSource("D:/temp/mylogo.png");
 imagePart.setDataHandler(new DataHandler(ds));
 imagePart.setHeader("Content-ID", "<mylogo.png>");
 imagePart.setDisposition(Part.INLINE);
 multipart.addBodyPart(imagePart);

当我在 yahoo 和 gmail 等电子邮件客户端中打开生成的邮件时,图像显示为我所期望的,但它也显示为附件。如何禁用下载此类图像?

【问题讨论】:

    标签: java jakarta-mail


    【解决方案1】:

    执行此操作时,图像将作为附件发送,因此显示为附件。您无法阻止这种情况,因为您对邮件客户端没有任何控制权。

    相反,将您的图片上传到网络上的某个位置,然后将您的 src 更改为其 URL。 (例如:&lt;img src="http://example.com/mylogo.png" /&gt;)。

    【讨论】:

    • 除了 URL 还有其他方法吗?
    【解决方案2】:

    这在移动邮件客户端上很正常,他们这样做是为了让人们可以在手机上下载邮件嵌入图像。如果您在计算机上打开它,图像将不会显示为附件。

    【讨论】:

      猜你喜欢
      • 2019-02-02
      • 2014-12-05
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 2016-08-02
      • 2013-05-27
      • 2011-04-16
      • 2019-12-12
      相关资源
      最近更新 更多