I want to access GMail messages from a Java application using JavaMail and IMAP. Why am I getting a SocketTimeoutException?
Here is my code:
Properties props = System.getProperties(); props.setProperty("mail.imap.host", "imap.gmail.com"); props.setProperty("mail.imap.port", "993"); props.setProperty("mail.imap.connectiontimeout", "5000"); props.setProperty("mail.imap.timeout", "5000"); try { Session session = Session.getDefaultInstance(props, new MyAuthenticator()); URLName urlName = new URLName("imap://MYUSERNAME@gmail.com:MYPASSWORD@imap.gmail.com"); Store store = session.getStore(urlName); if (!store.isConnected()) { store.connect(); } } catch (NoSuchProviderException e) { e.printStackTrace(); System.exit(1); } catch (MessagingException e) { e.printStackTrace(); System.exit(2); }
I set the timeout value so that it does not take "forever" until the timeout. In addition, MyAuthenticator also has a username and password, which seems superfluous with the URL. Is there any other way to specify a protocol? (I have not seen it in JavaDoc for IMAP.)
java imap gmail
Dave Sep 14 '08 at 7:11 2008-09-14 07:11
source share