4 Replies Latest reply: Dec 26, 2011 1:24 PM by Bill Shannon-Oracle RSS

    JavaMail: Store.Connect Error

    907023
      Hi,

      I am new to Javamail and I want to use Javamail to develop some sample email notification application.
      Looking forward for some Input.. Thanks

      Configuration and Setup:
      ===============
      1. I am running this on Fedora 14.
      2. Java1.6
      3. Using the monitor.java application to connect using IMAP to the store ie Root folder.
      4. Then monitors this folder for any new messages.
      5. I have provided the parameters in the run configuration.
      6. I am running the linux default sendmail server as MTA and Dovecot to support IMAP. All the applications MTA, Dovecot and JavaMail Email notification program are running in the same machine. There is no network involved here.

      I am able to get the Store for IMAP. However, while connecting to store I am getting the below error.

      Error:
      ====
      Session Created


      Store Accessed...

      javax.mail.MessagingException: * BYE Internal error occurred. Refer to server log for more information.;
      nested exception is:
           com.sun.mail.iap.ConnectionException: * BYE Internal error occurred. Refer to server log for more information.
           at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:663)
           at javax.mail.Service.connect(Service.java:295)
           at javax.mail.Service.connect(Service.java:176)
           at Monitor.main(Monitor.java:40)
      Caused by: com.sun.mail.iap.ConnectionException: * BYE Internal error occurred. Refer to server log for more information.
           at com.sun.mail.iap.Protocol.handleResult(Protocol.java:349)
           at com.sun.mail.imap.protocol.IMAPProtocol.authplain(IMAPProtocol.java:545)
           at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:716)
           at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:643)
           ... 3 more


      Source Code:
      =========

      import java.util.*;
      import java.io.*;
      import javax.mail.*;
      import javax.mail.event.*;
      import javax.activation.*;

      import com.sun.mail.imap.*;

      /* Monitors given mailbox for new mail */

      public class monitor {

      public static void main(String argv[]) {
           if (argv.length != 5) {
           System.out.println(
                "Usage: monitor <host> <user> <password> <mbox> <freq>");
           System.exit(1);
           }
           System.out.println("\nTesting monitor\n");

           try {
           Properties props = System.getProperties();

           // Get a Session object
           Session session = Session.getInstance(props, null);
           // session.setDebug(true);

           // Get a Store object
           Store store = session.getStore("imap");

           // Connect
           store.connect(argv[0], argv[1], argv[2]);

           // Open a Folder
           Folder folder = store.getFolder(argv[3]);
           if (folder == null || !folder.exists()) {
                System.out.println("Invalid folder");
                System.exit(1);
           }

           folder.open(Folder.READ_WRITE);

           // Add messageCountListener to listen for new messages
           folder.addMessageCountListener(new MessageCountAdapter() {
                public void messagesAdded(MessageCountEvent ev) {
                Message[] msgs = ev.getMessages();
                System.out.println("Got " + msgs.length + " new messages");

                // Just dump out the new messages
                for (int i = 0; i < msgs.length; i++) {
                     try {
                     System.out.println("-----");
                     System.out.println("Message " +
                          msgs.getMessageNumber() + ":");
                     msgs[i].writeTo(System.out);
                     } catch (IOException ioex) {
                     ioex.printStackTrace();     
                     } catch (MessagingException mex) {
                     mex.printStackTrace();
                     }
                }
                }
           });
                     
           // Check mail once in "freq" MILLIseconds
           int freq = Integer.parseInt(argv[4]);
           boolean supportsIdle = false;
           try {
                if (folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder)folder;
                f.idle();
                supportsIdle = true;
                }
           } catch (FolderClosedException fex) {
                throw fex;
           } catch (MessagingException mex) {
                supportsIdle = false;
           }
           for (;;) {
                if (supportsIdle && folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder)folder;
                f.idle();
                System.out.println("IDLE done");
                } else {
                Thread.sleep(freq); // sleep for freq milliseconds

                // This is to force the IMAP server to send us
                // EXISTS notifications.
                folder.getMessageCount();
                }
           }

           } catch (Exception ex) {
           ex.printStackTrace();
           }
      }
      }
        • 1. Re: JavaMail: Store.Connect Error
          r035198x
          >
               com.sun.mail.iap.ConnectionException: * BYE Internal error occurred. Refer to server log for more information.
          Did the said server logs have more information?
          • 2. Re: JavaMail: Store.Connect Error
            907023
            Hi,

            I am running this project on Eclipse Indigo 3.1 editor. I am not sure how to check the server logs.

            I am passing the input parameters are like:

            127.0.0.1 root testrig /var/spool/mail/root 10
            • 3. Re: JavaMail: Store.Connect Error
              907023
              Also When I enabled the debug logs I got some more logs like this:

              Testing monitor


              Properties Configured

              DEBUG: setDebug: JavaMail version 1.4.4

              Session Created

              DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
              DEBUG: mail.imap.fetchsize: 16384
              DEBUG: mail.imap.statuscachetimeout: 1000
              DEBUG: mail.imap.appendbuffersize: -1
              DEBUG: mail.imap.minidletime: 10

              Store Accessed...

              DEBUG: trying to connect to host "127.0.0.1", port 143, isSSL false
              * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN] Dovecot ready.
              DEBUG IMAP: AUTH: PLAIN
              DEBUG: protocolConnect login, host=127.0.0.1, user=amber, password=<non-null>
              A0 AUTHENTICATE PLAIN
              +
              AGFtYmVyAHRlc3RyaWc=
              * BYE Internal error occurred. Refer to server log for more information.
              javax.mail.MessagingException: * BYE Internal error occurred. Refer to server log for more information.;
              nested exception is:
                   com.sun.mail.iap.ConnectionException: * BYE Internal error occurred. Refer to server log for more information.
                   at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:663)
                   at javax.mail.Service.connect(Service.java:295)
                   at javax.mail.Service.connect(Service.java:176)
                   at Monitor.main(Monitor.java:42)
              Caused by: com.sun.mail.iap.ConnectionException: * BYE Internal error occurred. Refer to server log for more information.
                   at com.sun.mail.iap.Protocol.handleResult(Protocol.java:349)
                   at com.sun.mail.imap.protocol.IMAPProtocol.authplain(IMAPProtocol.java:545)
                   at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:716)
                   at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:643)
                   ... 3 more


              Any direction in this regard will be helpful...Thanks
              • 4. Re: JavaMail: Store.Connect Error
                Bill Shannon-Oracle
                You need to figure out how to check the server logs.