2014-03-24 84 views
0

我想在Android上的Javamail通過imap閱讀郵件。 這是我的代碼,但它不起作用。它提供了錯誤 請求時失敗:java.net.SocketException異常:沒有協議Javamail Android:似乎無法連接

支持地址族PLZ張貼工作代碼爲Android的JavaMail會話的imap

public void onClick(View v) { 
    // TODO Auto-generated method stub 
    Log.d("Click","Click"); 
    new read().execute(); 

} 
public class read extends AsyncTask<Void, Void, Void> 
{ 


    @Override 
    protected Void doInBackground(Void... params) { 

     String url = null; 
      String protocol = "imap"; 
      String host = "localhost"; 
      String user = "user"; 
      String password = "passowrd"; 

      try { 
      // Get a Properties object 
      Properties props = System.getProperties(); 

      // Get a Session object 
      Session session = Session.getInstance(props, null); 

      // Get a Store object 
      Store store = null; 
      if (url != null) { 
      URLName urln = new URLName(url); 
      store = session.getStore(urln); 
      store.connect(); 
      } else { 
      if (protocol != null) 
      store = session.getStore(protocol); 
      else 
      store = session.getStore(); 

      // Connect 
      if (host != null || user != null || password != null) 
      store.connect(host, user, password); 
      else 
      store.connect(); 
      } 

      // Open the Folder 
      String mbox = "INBOX"; 
      Folder folder = store.getDefaultFolder(); 
      if (folder == null) { 
      System.out.println("No default folder"); 
      System.exit(1); 
      } 

      folder = folder.getFolder(mbox); 
      Message[] messages = folder.getMessages(); 
      Log.v("unread", ""+folder.getUnreadMessageCount()); 

} 
      catch (Exception e) { 
      // TODO: handle exception 
     } 
      return null; 
+0

您正在連接到本地主機並在手機上運行。我懷疑你會在那裏找到一個IMAP服務器。 – arnt

+0

我不認爲這樣的情況...因爲發送電子郵件程序沒有任何問題.. – user3423795

+0

「發送電子郵件程序」也做...連接(「本地主機」,...)? – arnt

回答

0

佑,這是不應該的!您是否嘗試連接到僅支持IPv4的設備上的IPv6主機,反之亦然?如果打開JavaMail會話調試,調試輸出會顯示什麼內容?