简体   繁体   中英

Don't want Images as an attachment but need it inline

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:

  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);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM