title: Setting Content-Type for MimeMessage?
body: <p>I have one confusion about content type of mime message. Say I have a mime message. It is a multipart message and the body parts are like this</p>
  
  <ol>
  <li>Mime body part containing plain text, html text(like some letters in
  bold in body)</li>
  <li>Second mime body part containing an attachment,</li>
  <li>Third mime body part containing one inline image (which is being referred from body with cid)</li>
  </ol>
  
  <p>When I am creating the body part, should I explicitly set the content type for top mime message and then each body part?</p>
  
  <p>If yes, what should they be in the above example? </p>
  
  <p><code>multipart/alternative</code> is suggested for html, <code>multipart/mixed</code> is suggested for attachments, <code>multipart/related</code> is suggested for inline. I am using all of them, so what should be content-Type for complete message and different body parts?</p>
  
  <p>Just for information I tried to replicate above scenario where I did not set the  content type neither for the overall MimeMessage nor for body parts.</p>
  
  <p>But still I get the expected stuff like plain text, Bold letters in body, attachment, inline image on james at right place </p>
  
  <p>How come James is interpreting the mime message and body parts without setting the content type, and how come it is displaying them in right fashion?</p>
  
  <p><strong>Code For Reference</strong></p>
  
  <pre><code>  MimeMessage   msg = new MimeMessage(mailSession);
    MimeMultipart mpart = new MimeMultipart();
    MimeBodyPart bp = new MimeBodyPart();
    bp.setText("plain text and html text like&lt;b&gt;Test&lt;/&gt;", CHARSET_UTF_8, MESSAGE_HTML_CONTENT_TYPE);
    // add message body
    mpart.addBodyPart(bp);
  
   // adding attachment
    MimeBodyPart bodyPart = new MimeBodyPart();
    bodyPart.setFileName("WordFile1");
    file = new File("word file");
    DataSource source = new FileDataSource(file);
    bodyPart.setDataHandler(new DataHandler(source));
    mpart.addBodyPart(bodyPart);
  
  
   // adding image inline
    MimeBodyPart bodyPart2 = new MimeBodyPart();
    bodyPart2.setFileName("inline image");
    file2 = new File("image1");
    DataSource source2 = new FileDataSource(file);
    bodyPart2.setDataHandler(new DataHandler(source));
    bodyPart2.setDisposition(MimeBodyPart.INLINE);
    bodyPart2.setHeader("Content-ID", "Unique-CntentId");
    bodyPart2.setHeader("Content-Type", "image/jpeg");
    mpart.addBodyPart(bodyPart2);
  
    // At last setting multipart In MimeMessage
    msg.setContent(mpart);
  </code></pre>
  
  <p>With the above code, I get the correct html text, plain text, inline image and  attachments at right place in ThunderBird integrated with James. </p>
  
  <p>So I don't understand when and where to set <code>multipart/mixed</code>, <code>multipart/alternative</code>, <code>multipart/related</code> as Content-Type or does the mail server internally set it?</p>