title: javamail api to access gmail inbox messages
body: <p>I have been trying to use the javamail api to read gmail inbox messages. I found the following code on the internet. I'm trying to run this on Eclipse, but it is failing with an "Invalid credentials exception". I have mail.jar, activation.jar, imap.jar and other jar files in the lib directory of the web-app. </p>
  
  <p>Any ideas as to why I am receiving this exception ?  Thanks.</p>
  
  <pre><code>javax.mail.AuthenticationFailedException: Invalid credentials n67if632335wep.219
  at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665)
  at javax.mail.Service.connect(Service.java:295)
  at javax.mail.Service.connect(Service.java:176)
  at org.mb.mail.MailReader.main(MailReader.java:23)
  
  
  package org.mb.mail;
  
  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 javax.mail.Store;
  import javax.mail.*;
  
  public class MailReader {
  
  public static void main(String args[]) {
  Properties props = System.getProperties();
  props.setProperty("mail.store.protocol", "imaps");
  try {
  Session session = Session.getDefaultInstance(props, null);
  Store store = session.getStore("imaps");
  store.connect("imap.gmail.com", "&lt;username&gt;", "password");
  System.out.println(store);
  
  Folder inbox = store.getFolder("Inbox");
  inbox.open(Folder.READ_ONLY);
  Message messages[] = inbox.getMessages();
  for(Message message:messages) {
  System.out.println(message);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>        } catch (NoSuchProviderException e) {
              e.printStackTrace();
              System.exit(1);
          } catch (MessagingException e) {
              e.printStackTrace();
              System.exit(2);
          }
  
      }
  
  }
  </code></pre>