I have to send email from Java application. The email content is a HTML file with images. When I load in my application, I am able to see the images. But after sending it as an email, I am not able to see the images inside the HTML in email. I have tried attaching those images as an inline images. It is not working. I can see those images in attachment but not inside the content/body. Please help me. Please see the code below.
Map<String, String> inlineImages = new HashMap<String, String>();
for (int co=0; co<attachments.size(); co++){
inlineImages.put(Math.random()+"", "E:\\eclipse-workspace\\Demo\\src\\images\\EmailTemplatesOutput\\assets\\"+attachments.get(co));
}
// adds inline image attachments
if (inlineImages != null && inlineImages.size() > 0) {
Set<String> setImageID = inlineImages.keySet();
for (String contentId : setImageID) {
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setHeader("Content-ID", "<" + contentId + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
String imageFilePath = inlineImages.get(contentId);
try {
imagePart.attachFile(imageFilePath);
} catch (IOException ex) {
ex.printStackTrace();
}
multipart.addBodyPart(imagePart);
}
}
emailMessage.setContent(multipart);