title: why is html content not displayed in email with attachments
body: <p>I am using JavaMail to send E-mails with html content and attachments. But when sending an E-mail containing both html content and attachments, the html content is diplayed as plain text.</p>
  
  <p>I have set the <code>Content-Type</code> headers as <code>text/html; charset=us-ascii</code> but in the E-mail I receive, the <code>Content-Type</code> is shown as <code>text/plain</code>. Why is this happening?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>if(f!=null){ // f is an array containing the attachment file objects
                  Multipart mp=new MimeMultipart("mixed");
                  BodyPart mbody=new MimeBodyPart();
                  mbody.setHeader("Content-Type", "text/html; charset=us-ascii");
                  mbody.setHeader("Content-Transfer-Encoding","7bit");
                  mbody.setText(content);                               
                  mp.addBodyPart(mbody);                                        
                  for(File file:f){    
                      BodyPart mbody2=new MimeBodyPart();
                      DataSource ds=new FileDataSource(file.getAbsolutePath());
                      mbody2.setDataHandler(new DataHandler(ds));
                      mbody2.setFileName(ds.getName());
                      System.out.println(ds.getName());
                      mbody2.setHeader("Content-Type", "multipart/mixed");
                      mp.addBodyPart(mbody2);                        
                  }
                  m.setContent(mp);
                  //m.setHeader("Content-Type", "multipart/mixed");
                  //m.setHeader("Content-Transfer-Encoding","base64");
              }
              else{
                  m.setContent(content,"text/html");
                  m.setHeader("Content-Type", "text/html; charset=us-ascii");
                  m.setHeader("Content-Transfer-Encoding","7bit");
              }
              m.saveChanges();
  </code></pre>
  
  <p>If I uncomment <code>m.setHeader("Content-Type", "multipart/mixed");</code>, then the attachment(s) are displayed as noname without an extension and the content isn't present at all.</p>
  
  <p>If I send the E-mail without attachments, the html content is displayed properly.</p>
  
  <p>Thanks for any help.</p>