views:

151

answers:

1

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?

A: 
Bernardo