Java mail API problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vigupta12
    New Member
    • Jan 2007
    • 1

    #1

    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 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
  • rengaraj
    New Member
    • Jan 2007
    • 168

    #2
    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.

    Comment

    • rengaraj
      New Member
      • Jan 2007
      • 168

      #3
      The below code can help you

      messageBodyPart = new MimeBodyPart();
      DataSource fds = new FileDataSource
      ("Images/currency.jpg");
      messageBodyPart .setDataHandler (new DataHandler(fds ));
      messageBodyPart .setHeader("Con tent-ID","<image>" );

      // add it
      multipart.addBo dyPart(messageB odyPart);

      Source: http://forum.java.sun. com/thread.jspa?thr eadID=5130082&m essageID=946616 6#9466166

      Comment

      Working...