2

在 ios10 邮件应用程序中,内联图像显示为 0 字节的“点击下载,mime-attachment”。单击时,图像将不会被下载。在浏览器和 gmail 应用程序中,它工作正常,甚至在 ios8 和 9 邮件应用程序中。下面是代码

        MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper;

    try {
        helper = new MimeMessageHelper(message, true);
        helper.setSubject(emailVO.getSubject());

        helper.setTo(emailVO.getEmailTo());
        helper.setText(emailVO.getBody(), true);

        // substitute image logo
        ClassPathResource logoResource = new ClassPathResource("mailLogo.PNG");

        helper.addInline("imageLogo", logoResource,"image/png");

        ClassPathResource fbLogoResource = new ClassPathResource("facebookIcon.PNG");

        helper.addInline(fbLogo, new File(fbLogoResource.getURI()));

        helper.setFrom(emailVO.getFromEmailID());

        LOG.info("Sending Email to " + emailVO.getEmailTo());
        javaMailSender.send(message);
        LOG.info("Sent Email to " + emailVO.getEmailTo());
    } catch (MessagingException e) {
        LOG.error("Messaging Exception while sending email" , e);
        throw new SystemException("Messaging Exception while sending email");
    } catch (IOException e) {
        LOG.error("I/O Exception while sending email" , e);
        throw new SystemException("I/O Exception while sending email");
    }  

下面是在 MimeMessageHelper 类内部调用的 addInline 方法。

     public void addInline(String contentId, DataSource dataSource) throws 
     MessagingException {
    Assert.notNull(contentId, "Content ID must not be null");
    Assert.notNull(dataSource, "DataSource must not be null");
    MimeBodyPart mimeBodyPart = new MimeBodyPart();
    mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
    // We're using setHeader here to remain compatible with JavaMail 1.2,
    // rather than JavaMail 1.3's setContentID.
    mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
    mimeBodyPart.setDataHandler(new DataHandler(dataSource));
    getMimeMultipart().addBodyPart(mimeBodyPart);
}

我为 2 个内联图像尝试了 2 种不同的方法,即只为其中一个图像 fbLogo 传递 contentId 和 File,另一个通过显式传递 imageLogo 的内容类型。ContentId 在 html 文件中传递给 src 属性。

      <img style="vertical-align: text-bottom; padding-right: 15px;" height="22px" width="144px" src="cid:imageLogo"/>

这两种方法都不适用于 ios10 邮件应用程序。请帮忙。

4

0 回答 0