Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java mail Store.connect hangs - doesn't timeout

984643Jan 14 2013 — edited Jan 23 2013
I am using Java mail api to programming on receiveing mail of various of mail box(pop3/Imap) by multithread.
for each mailbox, before calling store.getFolder("INBOX"), I called the follow function to connect to Imap server

public void initStore(){
synchronized (syncObj)
{
if(store == null || !store.isConnected()){

Properties prop = new Properties();

prop.setProperty("mail.imap.host", imapserver);

prop.setProperty("mail.imap.auth.plain.disable", "true");

if(isSsl){//if user set isSsl to “true” when config the mailbox

String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
prop.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
prop.setProperty("mail.imap.socketFactory.fallback", "false");
prop.setProperty("mail.imap.port", "993");
prop.setProperty("mail.imap.socketFactory.port", "993");

prop.setProperty("mail.imap.partialfetch", "false");
prop.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true");

}

try
{

Session mailsession=Session.getInstance(prop,null);

session = mailsession;
mailsession.setDebug(true);

store = (IMAPStore)mailsession.getStore("imap");
store.connect(imapserver,user,pwd);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

usually,it works normal,but somtimes,it hangs at "store.connect(imapserver,user,pwd);"

Debug Info:
DEBUG: setDebug: JavaMail version 1.4.5

DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.partialfetch: false
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: disable AUTH=PLAIN
DEBUG: trying to connect to host "imap.gmail.com", port 993, isSSL false
* OK Gimap ready for requests from 219.149.12.125 m26if10520967yhn.37
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2
A0 OK Thats all she wrote! m26if10520967yhn.37
DEBUG IMAP: AUTH: XOAUTH
DEBUG IMAP: AUTH: XOAUTH2
DEBUG: protocolConnect login, host=imap.gmail.com, user=tracyamazon087@gmail.com, password=<non-null>
DEBUG IMAP: LOGIN command trace suppressed//after here, there are nothing to output by debug


How should I do to resolve these? Waiting For your answer,Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2013
Added on Jan 14 2013
4 comments
12,901 views