By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Java mail API problem

P: 1
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")));

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

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
Jan 23 '07 #1
Share this Question
Share on Google+
2 Replies

P: 168
Your Content-ID should be in angle brackets, and you might as well
use the method designed for this purpose:

MimeBodyPart messageBodyPart = new MimeBodyPart();

That might help.
Jan 30 '07 #2

P: 168
The below code can help you

messageBodyPart = new MimeBodyPart();
DataSource fds = new FileDataSource
messageBodyPart.setDataHandler(new DataHandler(fds));

// add it

Source: 6166
Jan 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.