title: Using JavaMail to read the mail
body: <p>I am getting this error when tried to read mail using JavaMail. please let me know how to resolve this error. I have added <em>activation.jar</em> and <em>mail.jar</em> into eclipse.</p>
  
  <pre><code>DEBUG POP3: server doesn't support TOP, disabling it
  javax.mail.AuthenticationFailedException: Command is not valid in this state.
  at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:174)
  at javax.mail.Service.connect(Service.java:291)
  at javax.mail.Service.connect(Service.java:172)
  at library.VerifyEmail.main(VerifyEmail.java:40)
  </code></pre>
  
  <p>Below is the code I am trying:</p>
  
  <pre><code>package library;
  
  import java.io.IOException;
  import java.util.Properties;
  import javax.mail.Folder;
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.NoSuchProviderException;
  import javax.mail.Session;
  import com.sun.mail.pop3.POP3Store;
  
  import java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import javax.mail.search.SubjectTerm;
  import javax.activation.*;
  import java.io.*;
  public class VerifyEmail {
  public static void main(String[] args) throws Exception {
       // SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
      String host = "myhost";
      // SUBSTITUTE YOUR USERNAME AND PASSWORD TO ACCESS E-MAIL HERE!!!
      String user = "myuser";
      String password = "mypass";
  
   // Get a session.  Use a blank Properties object.
      Session session = Session.getInstance(new Properties());
      try {
          // Get a Store object
          Store store = session.getStore("pop3");
          store.connect(host, user, password);
  
          // Get "INBOX"
          Folder fldr = store.getFolder("INBOX");
          fldr.open(Folder.READ_WRITE);
          int count = fldr.getMessageCount();
          System.out.println(count  + " total messages");
  
          // Message numebers start at 1
          for(int i = 1; i &lt;= count; i++) {
              // Get  a message by its sequence number
              Message m = fldr.getMessage(i);
           // Get some headers
              Date date = m.getSentDate();
              Address [] from = m.getFrom();
              String subj = m.getSubject();
              String mimeType = m.getContentType();
              System.out.println(date + "\t" + from[0] + "\t" +
                                  subj + "\t" + mimeType);
          }
  
      }catch (MessagingException  ioex) {
          ioex.printStackTrace();
      }
  }
  }
  </code></pre>