title: Cannot connect to mailserver using javamail
body: <p>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...</p>
  
  <p>This is My code :</p>
  
  <pre><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");
   ...
   ...
  </code></pre>
  
  <p>The exception is being thrown from here at :</p>
  
  <pre><code> store.connect(...
  </code></pre>
  
  <p>Exception is :</p>
  
  <pre><code>    java.mail.MessagingException : Connection refused : connect;
       nested exception is :
       java.net.ConnectionException: Connection refused : connect
  </code></pre>
  
  <p>Knowing that the result of telnet process is :</p>
  
  <pre><code>   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
  </code></pre>
  
  <p>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 ?</p>