Reputation: 36640
I'm using plain old java mail (mail-1.4.1.jar - JVM 1.6.0_03-b05) to connect to an IMAP store:
Session mailSession = Session.getInstance(new Properties(), null);
Store store = mailSession.getStore("imap");
store.connect(host, user, pwd); // Hangs here
folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
...
Problem is, occasionally the thread hands at store.connect
and never returns.
"MyThread" daemon prio=10 tid=0x0a9c3000 nid=0x2095 runnable [0x9ccd3000..0x9ccd4130]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
- locked <0xc09003e8> (a java.io.BufferedInputStream)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:97)
at com.sun.mail.iap.Response.<init>(Response.java:96)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:61)
at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:135)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:261)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:114)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
- locked <0xc04c73d0> (a com.sun.mail.imap.IMAPStore)
at javax.mail.Service.connect(Service.java:288)
- locked <0xc04c73d0> (a com.sun.mail.imap.IMAPStore)
at javax.mail.Service.connect(Service.java:169)
at package.MyClass.checkInbox(MyClass.java:116)
There is no mention of timeout settings in the javamail spec and I cannot find any suitable 'setter' methods on either Session
or Store
.
Any suggestions welcome.
Upvotes: 2
Views: 3102
Reputation: 29971
See the javadocs for the com.sun.mail.imap package for the properties you can set to control (among other things) timeouts. Oh, and you probably want to upgrade to the latest version of JavaMail.
Upvotes: 1