0

I have this code to include images in email using Java.

MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource imageSource = new ByteArrayDataSource(imageToByteArray(image, format), type);
messageBodyPart.setDataHandler(new DataHandler(imageSource));
messageBodyPart.setContentID(imageContentID);
multipart.addBodyPart(messageBodyPart);

But my images are shown as attachments as well as inline. What is wrong in it ?

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
  • 1
    Possibly related: [Inline images in email using JavaMail](https://stackoverflow.com/questions/2996514/inline-images-in-email-using-javamail). – Slaw Jan 07 '20 at 08:13

1 Answers1

0

Couple of things:

  1. I had not set filename in the body part.

    messageBodyPart.setFileName(fileName);

  2. I was setting format and type as "jpg","image/jpg" respectively instead of "png","image/png"

    DataSource imageSource = new ByteArrayDataSource(imageToByteArray(image, format), type);

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55