title: Embedding images into html email with java mail
body: <p>I am sending html and images with javamail but for some reason I don't see the images as part of the html, I see them only as an attachment. I don't know why is that. This is how it looks like when one of my users receive an email: 
  <img src="https://i.stack.imgur.com/iLoVf.png" alt="enter image description here"></p>
  
  <p>I would like to mention also that is how the html looks like:</p>
  
  <pre><code>private String generateActivationLinkTemplate() {
      String htmlText = "";
  htmlText ="&lt;table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"&gt;  &lt;tr&gt;    &lt;td&gt;&lt;img src=\"cid:logoimg\"/&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;td height=\"220\"&gt; &lt;p&gt;Thanks for Joining Site.com&lt;/p&gt;      &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. &lt;/p&gt;    &lt;p&gt;Username:&lt;br /&gt;      Password: &lt;/p&gt;    &lt;p&gt;To confirm your email click &lt;a href=\"#\"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;td height=\"50\" align=\"center\" valign=\"middle\" bgcolor=\"#CCCCCC\"&gt;www.site.com | contact@site.com | +38200 123 456&lt;/td&gt;  &lt;/tr&gt;&lt;/table&gt;";}
  </code></pre>
  
  <p>Do I need an html,body, and a head tag...?</p>
  
  <p>This is how the java implementation looks like:</p>
  
  <pre><code>@Stateless(name = "ejbs/EmailServiceEJB")
  public class EmailServiceEJB implements IEmailServiceEJB {
  
  @Resource(name = "mail/myMailSession")
  private Session mailSession;
  
  public void sendAccountActivationLinkToBuyer(String destinationEmail,
          String name) {
  
      // Destination of the email
      String to = destinationEmail;
      String from = "dontreply2thismessage@gmail.com";
  
      try {
          Message message = new MimeMessage(mailSession);
          // From: is our service
          message.setFrom(new InternetAddress(from));
          // To: destination given
          message.setRecipients(Message.RecipientType.TO,
                  InternetAddress.parse(to));
          message.setSubject("Uspijesna registracija");
          // How to found at http://www.rgagnon.com/javadetails/java-0321.html
          message.setContent(generateActivationLinkTemplate(), "text/html");
  
          Date timeStamp = new Date();
          message.setSentDate(timeStamp);
  
          // Prepare a multipart HTML
          Multipart multipart = new MimeMultipart();
          // Prepare the HTML
          BodyPart htmlPart = new MimeBodyPart();
          htmlPart.setContent(generateActivationLinkTemplate(), "text/html");
  
          // PREPARE THE IMAGE
          BodyPart imgPart = new MimeBodyPart();
  
          String fileName = "logoemailtemplate.png";
  
          ClassLoader classLoader = Thread.currentThread()
                  .getContextClassLoader();
          if (classLoader == null) {
              classLoader = this.getClass().getClassLoader();
              if (classLoader == null) {
                  System.out.println("IT IS NULL AGAIN!!!!");
              }
          }
  
          DataSource ds = new URLDataSource(classLoader.getResource(fileName));
  
          imgPart.setDataHandler(new DataHandler(ds));
          imgPart.setHeader("Content-ID", "logoimg");
  
          multipart.addBodyPart(imgPart);
          multipart.addBodyPart(htmlPart);            
  
          // Set the message content!
          message.setContent(multipart);
  
          Transport.send(message);
  
      } catch (MessagingException e) {
          throw new RuntimeException(e);
      }
  
  }
  </code></pre>
  
  <p>I think the java part to me looks fine, but i am suspicious only is the html markup, i there something wrong with it? I think that the img tag is not working properly and for not reason the image dont appear on the email(Notice it only appears down as an attachment):</p>
  
  <pre><code>&lt;img src=\"cid:logoimg\"/&gt;
  </code></pre>