Getting mail from GMail into Java application using IMAP -


i want access messages in gmail java application using javamail , imap. why getting sockettimeoutexception ?

here 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 timeout values wouldn't take "forever" timeout. also, myauthenticator has username , password, seems redundant url. there way specify protocol? (i didn't see in javadoc imap.)

using imaps great suggestion. neither of answers provided worked me, googled more , found worked. here's how code looks now.

properties props = system.getproperties(); props.setproperty("mail.store.protocol", "imaps"); try {   session session = session.getdefaultinstance(props, null);   store store = session.getstore("imaps");   store.connect("imap.gmail.com", "<username>@gmail.com", "<password>");   ... } catch (nosuchproviderexception e) {   e.printstacktrace();   system.exit(1); } catch (messagingexception e) {   e.printstacktrace();   system.exit(2); } 

this nice because takes redundant authenticator out of picture. i'm glad worked because sslnotes.txt make head spin.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -