views:

633

answers:

2

Hi All:
I want to send mail along with embedded image. For that i have used the below code. Its not full code. Its a part of code

        Multipart multipart = new MimeMultipart("related");
  // Create the message part 
  BodyPart messageBodyPart;
  messageBodyPart = new MimeBodyPart();
  messageBodyPart.setText(msgBody); // msgbody contains the contents of the html file
  messageBodyPart.setHeader("Content-Type", "text/html");
  multipart.addBodyPart(messageBodyPart);

  //add file attachments
  DataSource source;
  File file = new File("D:/sample.jpeg");
  if(file.exists()){
   // add attachment
   messageBodyPart = new MimeBodyPart();
   source = new FileDataSource(file);
   messageBodyPart.setDataHandler(new DataHandler(source));
   messageBodyPart.setFileName(file.getName());
   messageBodyPart.setHeader("Content-ID", "<BarcodeImage>");
   messageBodyPart.setDisposition("inline");
   multipart.addBodyPart(messageBodyPart);
  }

  // Put parts in message
  msg.setContent(multipart);
  Transport.send(msg);

Problem i am facing is, i can get the mail but cant acle to see the image.. Its not get displaying in the mail.
Below is my part of html file

             <img src=\"cid:BarcodeImage\" alt="Barcode" width="166" height="44" align="right" />

Please help me why the image not getting displayed in the mail and why it is not in the attachment??

A: 

please help me.. I am strucking with this problem for last two days

A: 

Try getting rid of the following line:

                        messageBodyPart.setDisposition("inline");
objects