inline images in email using javamail

Posted by manu1001 on Stack Overflow See other posts from Stack Overflow or by manu1001
Published on 2010-06-08T10:29:49Z Indexed on 2010/06/09 5:22 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|

I want to send an email with an inline image using javamail.

I'm doing something like this.

MimeMultipart content = new MimeMultipart("related");

BodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent(message, "text/html; charset=ISO-8859-1");
content.addBodyPart(bodyPart);

bodyPart = new MimeBodyPart();
DataSource ds = new ByteArrayDataSource(image, "image/jpeg");
bodyPart.setDataHandler(new DataHandler(ds));
bodyPart.setHeader("Content-Type", "image/jpeg; name=image.jpg");
bodyPart.setHeader("Content-ID", "<image>");
bodyPart.setHeader("Content-Disposition", "inline");
content.addBodyPart(bodyPart);

msg.setContent(content);

I've also tried

    bodyPart.setHeader("inline; filename=image.jpg");

and

    bodyPart.setDisposition("inline");

but no matter what, the image is being sent as an attachment and the Content-Dispostion is turning into "attachment".

How do I send an image inline in the email using javamail?

© Stack Overflow or respective owner

Related posts about java

Related posts about mime