0

I am trying to connect to IMAP server to read mails knowing that the IMAP mailserver is a local APache JAMES Mailserver. When using pop3 protocol, everything succeed, sending / retrieving messages between clients... But when i changed the protocol to imap, connection exceptiion is being thrown i dunno why...

This is My code :

 @Stateless
 public class Mailer{

 @Resouces(name = "mail/javamailsession")
 private Session session;

 public void connect(){
 IMAPStore store = (IMAPStore)session.getStore("imap");
 store.connect("localhost","test@mydomain.org","myPass");
 ...
 ...

The exception is being thrown from here at :

 store.connect(...

Exception is :

    java.mail.MessagingException : Connection refused : connect;
     nested exception is :
     java.net.ConnectionException: Connection refused : connect

Knowing that the result of telnet process is :

   Me  :     telnet localhost imap
   Cmd :     Ok James IMAP4rev1 server server pc_name is ready
   Me  :     01 login test@localhost 123456
   Cmd :     01 Ok login completed

This means in a way or another that the imap is enabled in the server... So why should such exception occur :S Anybody has an idea ?

primeFaceUser
  • 295
  • 2
  • 15

1 Answers1

0

Most likely you have a firewall or anti-virus product that's allowing the connection from telnet but preventing the connection from your application. It looks like your application is a Java EE application. I assume the Java EE server is running on the same machine that the mail server is on, and that you ran telnet from.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • I missed to tell you that i am working in a virtual machine, could that be the reason behind this connection problem ? – primeFaceUser Sep 09 '13 at 17:21
  • If everything is running in the same virtual machine, that seems unlikely. Just to be sure, the JAMES mail server, the application server running your program, and the telnet command are all running in that same virtual machine, right? – Bill Shannon Sep 09 '13 at 18:39
  • Yes , everything is running on the same virtual machine. For now, i prepared my environment on another virtual machine and lunched my application and fortunately everything is working. There is no connection problem ! The same environment (James, JavaMail, Glassfish) works on a virtual machine but doesn't on another. knowing that on both machine, no firewall and also no antivirus. – primeFaceUser Sep 10 '13 at 16:04
  • I am still not sure about the reason behind this problem. – primeFaceUser Sep 10 '13 at 16:04