Java mail API problem

Hi List,

I am using java mail API. I have to embed an image with my html content.

Here is the sample code that I am using for this.

MimeMultipart multipart = new MimeMultipart("related");

String imagefile = "E:/data//image002.gif";

try {

// Create your new message part

BodyPart messageBodyPart = new MimeBodyPart();

String htmlText = "Hello";

messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(htmlText,"text/html")));

multipart.addBodyPart(messageBodyPart);

// Create part for the image

messageBodyPart = new MimeBodyPart();

// Fetch the image and associate to part

DataSource fds = new FileDataSource(imagefile);

messageBodyPart.setDataHandler(new DataHandler(fds));

messageBodyPart.setHeader("Content-ID", "test_001");

messageBodyPart.setDisposition("inline");

message.setContent(multipart);

I am able to get an email as required with embedded image in OUTLOOK.

But It is not displaying images inline in gmail and yahoo.

I am unable to get where I am wrong?

Thanks in advance

source: http://www.thescripts.com/forum/thread591812.html

[1202 byte] By [rengaraja] at [2007-11-26 16:34:42]
# 1

Your Content-ID should be in angle brackets, and you might as well

use the method designed for this purpose:

MimeBodyPart messageBodyPart = new MimeBodyPart();

...

messageBodyPart.setContentID("<test_001>");

That might help.

bshannona at 2007-7-8 22:59:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

The below code can help you

messageBodyPart = new MimeBodyPart();

DataSource fds = new FileDataSource

("Images/currency.jpg");

messageBodyPart.setDataHandler(new DataHandler(fds));

messageBodyPart.setHeader("Content-ID","<image>");

// add it

multipart.addBodyPart(messageBodyPart);

Ashitosha at 2007-7-8 22:59:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...