Javamail Android:似乎无法连接

时间:2014-03-24 23:21:16

标签: android sockets javamail imap gmail-imap

我正在尝试使用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;

1 个答案:

答案 0 :(得分:0)

是的,这不应该发生!您是否尝试在仅支持IPv4的设备上连接到IPv6主机,反之亦然?如果打开JavaMail会话调试,调试输出会显示什么?