title: Cannot connect to Gmail IMAP using XOAUTH on Android
body: <p>I'm building an app that uses Gmail to backup some data. I use XOAUTH to connect to Gmail and got the token and secret. But i could not connect to Gmail's IMAP service. I followed the example at <a href="http://code.google.com/p/google-mail-xoauth-tools/wiki/JavaSampleCode" rel="nofollow">http://code.google.com/p/google-mail-xoauth-tools/wiki/JavaSampleCode</a>:</p>
  
  <pre><code>Properties props = new Properties();
  props.put("mail.imaps.sasl.enable", "true");
  props.put("mail.imaps.sasl.mechanisms", "XOAUTH");
  props.put(OAUTH_TOKEN_PROP, oauthToken);
  props.put(OAUTH_TOKEN_SECRET_PROP, oauthTokenSecret);
  props.put(CONSUMER_KEY_PROP, Const.CONSUMER_KEY);
  props.put(CONSUMER_SECRET_PROP, Const.CONSUMER_SECRET);
  Session session = Session.getInstance(props);
  session.setDebug(debug);
  
  final URLName unusedUrlName = null;
  IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
  final String emptyPassword = "";
  store.connect(host, port, userEmail, emptyPassword);
  return store;
  </code></pre>
  
  <p>When runs, it reports the following exception.</p>
  
  <pre><code>javax.mail.MessagingException: * BYE [UNAVAILABLE] Temporary System Error;
     nested exception is:
      com.sun.mail.iap.ConnectionException: * BYE [UNAVAILABLE] Temporary System Error
      at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:569)
      at javax.mail.Service.connect(Service.java:288)
      at com.doodlemobile.zy.finenote.OAuthHelperActivity$XoauthAuthenticator.connectToImap(OAuthHelperActivity.java:565)
      at com.doodlemobile.zy.finenote.OAuthHelperActivity$ConnectGmailTask.doInBackground(OAuthHelperActivity.java:484)
      at com.doodlemobile.zy.finenote.OAuthHelperActivity$ConnectGmailTask.doInBackground(OAuthHelperActivity.java:1)
      at android.os.AsyncTask$2.call(AsyncTask.java:287)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
      at java.util.concurrent.FutureTask.run(FutureTask.java:137)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
      at java.lang.Thread.run(Thread.java:856)
   Caused by: com.sun.mail.iap.ConnectionException: * BYE [UNAVAILABLE] Temporary System Error
      at com.sun.mail.iap.Protocol.handleResult(Protocol.java:346)
      at com.sun.mail.imap.protocol.IMAPProtocol.login(IMAPProtocol.java:336)
      at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:615)
      at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:549)
      ... 11 more
  </code></pre>
  
  <p>I used javamail of SUN. Anyone would help me ?</p>