title: read message and attachment name of the same mail using javamail
body: <p>i need to use java to view mails. from these mails i want to know the name of the attachment (if there is one) and i want to know the message. </p>
  
  <p>is it possible to not only print the name of the attachment but to also print the contents of the mail? currently i'm using the following code that get's only the name of the attachment or (if their is none) the message content.</p>
  
  <pre><code> Message[] message = folder.getMessages();
   //Display message.
   for (int i = 0; i &lt; message.length; i++) {
  
       System.out.println("------------ Message " + (i + 1) + " ------------");
  
       System.out.println("SentDate : " + message[i].getSentDate());
       System.out.println("From : " + message[i].getFrom()[0]);
       System.out.println("Subject : " + message[i].getSubject());
  
  
       Multipart multipart = (Multipart) message[i].getContent();
  
       for (int x = 0; x &lt; multipart.getCount(); x++) {
           BodyPart bodyPart = multipart.getBodyPart(x);
  
           String disposition = bodyPart.getDisposition();
  
           if (disposition != null &amp;&amp; (disposition.equals(BodyPart.ATTACHMENT))) {
  
               DataHandler handler = bodyPart.getDataHandler();
               System.out.println("Attachment : " + handler.getName());
  
           } else {
               System.out.println("Content: " + bodyPart.getContent());
           }
       }
  </code></pre>