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 ByteArrayDataSo urce(htmlText," text/html")));
multipart.addBo dyPart(messageB odyPart);
// 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("Con tent-ID", "test_001") ;
messageBodyPart .setDisposition ("inline");
message.setCont ent(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
vikas
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 ByteArrayDataSo urce(htmlText," text/html")));
multipart.addBo dyPart(messageB odyPart);
// 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("Con tent-ID", "test_001") ;
messageBodyPart .setDisposition ("inline");
message.setCont ent(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
vikas
Comment