I'm trying to access my email from Java, and it has issues in the connect stage.
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;
public class CheckingMails {
public static void main(String args[]) {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
System.out.println("aaaaaa");
store.connect("imap.gmail.com", "myaddress@gmail.com", "mypassword");
System.out.println("success");
} catch (NoSuchProviderException e) {
e.printStackTrace();
System.exit(1);
} catch (MessagingException e) {
e.printStackTrace();
System.exit(2);
}
}
}
Every time I run this code it will print "aaaaaa" telling me that it gets to just before the connection, but then before it can print "success" it takes about a minute and then times out, giving me this error:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: imap.gmail.com, 993; timeout -1`;
nested exception is: java.net.ConnectException: Operation timed out
How can I fix this?