In ios10 mail app, inline image is shown as 'tap to doownload , mime-attachment' with 0 bytes. On click, Image will not be downloaded. In browser and gmail app, it works fine and even in ios8 and 9 mail app.Below is the code
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");
}
Below is the addInline method called internally in the MimeMessageHelper class.
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);
}
I tried 2 different ways for 2 inline images i.e.by just passing the contentId and File for one of the image fbLogo and another by passing the content type explicitly for imageLogo.ContentId is passed in the html file for src attribute.
<img style="vertical-align: text-bottom; padding-right: 15px;" height="22px" width="144px" src="cid:imageLogo"/>
Both of the approaches are not working in ios10 mail app. Please help.