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 ?
Couple of things:
I had not set filename in the body part.
messageBodyPart.setFileName(fileName);
I was setting format and type as "jpg","image/jpg" respectively instead of "png","image/png"
DataSource imageSource = new ByteArrayDataSource(imageToByteArray(image, format), type);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.