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;
您正在連接到本地主機並在手機上運行。我懷疑你會在那裏找到一個IMAP服務器。 – arnt
我不認爲這樣的情況...因爲發送電子郵件程序沒有任何問題.. – user3423795
「發送電子郵件程序」也做...連接(「本地主機」,...)? – arnt