有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Apple或Mac Mail会打开所有附件图像,即使它们已嵌入

当我们从tomcat服务器发送电子邮件时,实现了MimeMultiPart,它可以在大多数邮件软件中正常打开,例如Gmail、Outlook等;安卓邮件。 但当它在Apple Mail上打开时,它会自动打开PDF和图像,这在手机(手机和平板电脑,因为笔记本电脑可以在命令中更改)中是永久性的

正如我在几个网站上读到的那样,这就是它为苹果设计的方式。 问题是,即使是被认为是隐藏附件的嵌入式系统也会显示出来。 这会产生双重图像,我们称之为邮件中通过html嵌入的图像

图像是一个标志,所以它总是通过电子邮件发送。我希望有一种不同的协议可以在Apple mail中使用。我还没有在网上看到类似的问题,所以我希望我们只是在使用一些不同的协议

    BodyPart messageBodyPart = new MimeBodyPart();
    String htmlText = message + "<img src=\"cid:image123\">";
    messageBodyPart.setContent(htmlText, "text/html; charset=UTF-8");

    MimeMultipart mp = new MimeMultipart("mixed");
    mp.addBodyPart(messageBodyPart);

    BodyPart imageBodyPart = new MimeBodyPart();
    String file = this.getClass().getClassLoader().getResource("images/Logo.gif").getFile();
    DataSource fds = new FileDataSource(file);
    imageBodyPart.setFileName("Logo.gif");
    imageBodyPart.setHeader("Content-ID","<image123>");
    imageBodyPart.setDisposition(Part.INLINE);

    mp.addBodyPart(imageBodyPart);

当我删除HTML代码时,它仍然会在Apple mail中显示附加的图像,但是,它不会在其他电子邮件软件中完全显示


共 (2) 个答案

  1. # 1 楼答案

    缺陷最终在生产过程中消失。 MIME结构与https://stackoverflow.com/a/23853079/4558510略有不同

    我所做的就是建造

    • 混合的+
      • 相关+
      • html
      • 内联图像
    • 附件:
    • 附件:

    由于某种原因,在撰写本文时,Yahoo online client没有显示这些附件,所以将alternative与附件一起略去。把它们混合在一起效果很好

    经过测试并与

    • Apple/IOS Mail(平板电脑Ipad 2)
    • Outlook Windows 7客户端
    • Outlook mobile(Android)
    • Gmail网络客户端
    • Gmail mobile(Android)
    • Android移动电子邮件(棒棒糖)
    • 雅虎网络客户端
    • 雅虎移动电子邮件(安卓)
    • Lotus Notes Windows 7客户端

    注:Android使用的是三星Note 4棒棒糖

    代码:

        BodyPart messageBodyPart = new MimeBodyPart();
        String htmlText = message + "<img src=\"cid:image123\">";
        messageBodyPart.setContent(htmlText, "text/html; charset=UTF-8");
    
        MimeMultipart mpRelated = new MimeMultipart("relative");
        mpRelated.addBodyPart(messageBodyPart);
    
        BodyPart imageBodyPart = new MimeBodyPart();
        String file = this.getClass().getClassLoader().getResource("images/Logo.gif").getFile();
        DataSource fds = new FileDataSource(file);
        imageBodyPart.setFileName("Logo.gif");
        imageBodyPart.setHeader("Content-ID","<image123>");
        imageBodyPart.setDisposition(Part.INLINE);
    
        mpRelated.addBodyPart(imageBodyPart);
    
        MimeMultipart mpMixed = new MimeMultipart("mixed");
        //Nest Related into mixed
        BodyPart relatedInMixed = new MimeBodyPart();
        relatedInMixed.setContent(mpRelated);
        mpMixed.addBodyPart(relatedInMixed);
    
        //TODO Add attachement to mpMixed
    
  2. # 2 楼答案

    我以前也见过这种行为,我记得这是因为iOS设备上的MIME头解析逻辑不同

    另一篇帖子(以及相应的答案)提到并应该指导你找到一个可行的解决方案:Problem sending multipart mail using ActionMailer

    祝你好运,请告诉我们你进展如何