I have the following code
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mimeMessage, false, "utf-8");
String htmlMsg = "<body><div style="padding-top: 1px"><table
style="width: 100%"> <tr> <td align="left"><img align="left"
src="cid:**image1**" style="margin-left: -7px; width: 50%;"></td>
<td align="right"><img align="right" src="cid:**image2**"
style="margin-left: 100px; width: 50%;"> </td> </tr> </table></div>
<body>"
Multipart multipart = new MimeMultipart("related");
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(htmlMsg, "text/html");
messageBodyPart.setDisposition(BodyPart.INLINE);
multipart.addBodyPart(messageBodyPart);
InternetHeaders headers = new InternetHeaders();
headers.addHeader("Content-Type", "image/png");
headers.addHeader("Content-Transfer-Encoding", "base64");
String base64EncodedImageContentByteArray="encdoe value";
String base64EncodedImageContentByteArray1 = "encoded value";
MimeBodyPart imagePart1 = new MimeBodyPart(headers,
base64EncodedImageContentByteArray.getBytes());
imagePart1.setDisposition(MimeBodyPart.INLINE);
imagePart1.setContentID("image1");
imagePart1.setFileName("image1.jpg");
MimeBodyPart imagePart2 = new MimeBodyPart(headers,
base64EncodedImageContentByteArray1.getBytes());
imagePart2.setDisposition(MimeBodyPart.INLINE);
imagePart2.setContentID("image2");
imagePart2.setFileName("image2.jpg");
multipart.addBodyPart(imagePart1);
multipart.addBodyPart(imagePart2);
multipart.addBodyPart(messageBodyPart);
mimeMessage.setContent(multipart);
mimeMessage.setHeader("MIME-Version", "1.0");
But when I received the mail the first image is not showing but the second image showing in the mail. For first image place it is showing cross. Also I need to attache multiple images(base64 encoded value) in the mail