title: how to embed multiple images while sending html email using Java mail
body: <p>I'm trying to send email from javamail. I'm embeding the images and using CID. But the problem is how do I embed multiple images in a single message. if I try to add in header.. it is just taking the last set header.  how do I add multiple images and reference using CID.</p>
  
  <pre><code>MimeMultipart multipart = new MimeMultipart("related");
  
      // first part  (the html)
      BodyPart messageBodyPart = new MimeBodyPart();
  //    BodyPart messageBodyPart = new MimeBodyPart();
      String htmlText = "&lt;H1&gt;Hello&lt;/H1&gt;&lt;br/&gt; &lt;p align=center&gt;&lt;img src=\"cid:senny\"&gt; &lt;/p&gt;";
      htmlText+="&lt;p align=center&gt;&lt;img src=\"cid:senny\"&gt; &lt;/p&gt;";
      htmlText+="&lt;p align=center&gt;&lt;img src=\"cid:image\"&gt; &lt;/p&gt;";
      messageBodyPart.setContent(htmlText, "text/html");
  
      // add it
      multipart.addBodyPart(messageBodyPart);
  
      // second part (the image)
      messageBodyPart = new MimeBodyPart();
      DataSource fds = new FileDataSource
        ("C:\\images\\cec_header_457.png");
      DataSource fds1 = new FileDataSource
      ("C:\\images\\cec_header_420.png");
      messageBodyPart.setDataHandler(new DataHandler(fds));
      messageBodyPart.setDataHandler(new DataHandler(fds1));
      messageBodyPart.addHeader("Content-ID","&lt;image&gt;");
      messageBodyPart.addHeader("Content-ID","&lt;senny&gt;");
      // add it
      multipart.addBodyPart(messageBodyPart);
  
      // put everything together
      message.setContent(multipart);
  </code></pre>