我正在尝试使用android上的Javamail来通过imap阅读邮件。 这是我的代码,但它不起作用。它给出了错误 请求时间失败:java.net.SocketException:协议不支持的地址族
plz发布android javamail Imap session的工作代码
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 :(得分:0)