Search code examples
jakarta-mailimapredhat

Connection timeout while reading mails via Javamail


Am trying to read mails from our mail server using Javamail api. The program works fine when am running it on eclipse in windows on my local system. When i move the same code to our linux environment it gets connection timed out error.

Do i need to install some package on linux or anything? I believe the port should be open else i wont be able to connect from my local network?

The code am using is as below:

properties.setProperty("mail.store.protocol", "imaps");
properties.put("mail.imaps.ssl.trust", "*");
session = Session.getInstance(properties, null);
store = session.getStore();
store.connect(mailServerName, userName, password);

Solution

  • You have first to check if you allowed to connect to your mail server from your lunix host , by issuing telnet like this : telnet host portcommand , some times it is either blocked by firewall or network antivirus. also you may behind a proxy server (You have to check all the above with your network admin).

    In case you are behind a proxy server, you have to set the proxy settings and credntials for the JVM. For this , look at answer at Chris Carruthers answer here.