Linked Questions

Popular Questions

I need to use cid embedded images, I'm using the following methods in java:

    MimeBodyPart messageBodyPart = new MimeBodyPart();
    byte[] imageDataBytes = Base64.getDecoder().decode(imageDataString);
    DataSource ds = new ByteArrayDataSource(imageDataBytes, "image/jpeg");
    messageBodyPart.setDataHandler(new DataHandler(ds));
    messageBodyPart.setContentID("<testImage>");
    messageBodyPart.setFileName("testImage.jpeg");
    messageBodyPart.setHeader("Content-Transfer-Encoding","base64");
    messageBodyPart.setHeader("X-Attachment-Id","testImage");
    messageBodyPart.setHeader("Content-Type","image/jpeg");
    messageBodyPart.setDisposition(MimeBodyPart.INLINE);
    emailBodyAndAttachments.addBodyPart(messageBodyPart);

it looks good in gmail, just like but in outlook and mac email client I see the image as an attached image:

outlook enter image description here

Is there a header that will make it not appear as an attachment?

There must be one because when I drag and drop images into gmail email, they appear without the attachment part and they also use cid.

That's how it looks when I send it from gmail and that's what I also want:

outlook enter image description here

These are the headers that gmail uses:

--0000000000004076a905f77e39cf
Content-Type: image/jpeg; name="pexels-lisa-fotios-1540258.jpg"
Content-Disposition: inline; filename="pexels-lisa-fotios-1540258.jpg"
Content-Transfer-Encoding: base64
Content-ID: <ii_lfjsr1aq0>
X-Attachment-Id: ii_lfjsr1aq0

/9j/4AAQSkZJRgABAQ..........

and these are the headers that I attached:

--_004_CAMNVZSzi1kPoPE3OoJQKBpjw6iFoN2GooxXSKEYAh4pafw4Sgmailg_
Content-Type: image/jpeg; name="testImage.jpeg"
Content-Description: testImage.jpeg
Content-Disposition: attachment; filename="testImage.jpeg"; size=3716152;
    creation-date="Thu, 23 Mar 2023 10:18:53 GMT";
    modification-date="Thu, 23 Mar 2023 10:19:19 GMT"
Content-ID: <testImage>
Content-Transfer-Encoding: base64
X-Attachment-Id: testImage

The image is referenced as cid in the HTML of course: enter image description here

Related Questions