Search code examples
jakarta-mail

Exception in thread "main" javax.mail.MessagingException: Folder is not using SocketChannels


Using idle manager this exception appears: Exception in thread "main" javax.mail.MessagingException: Folder is not using SocketChannels

How can i solve this problem ?

ExecutorService es = Executors.newCachedThreadPool();
final IdleManager idleManager = new IdleManager(session, es);


folder.open(Folder.READ_WRITE);
            folder.addMessageCountListener(new MessageCountAdapter() {
                public void messagesAdded(MessageCountEvent ev) {
             Folder folder = (Folder)ev.getSource();
             Message[] msgs = ev.getMessages();
             System.out.println("Folder: " + folder +
                 " got " + msgs.length + " new messages");
                    try {
                        // process new messages
                        System.out.println("***********************process new messages : ");

                        idleManager.watch(folder); // keep watching for new messages
                    } catch (IOException | MessagingException ex) {
                        Logger.getLogger(mail2.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });

            idleManager.watch(folder); 

Solution

  • As the IdleManager javadocs say:

    .. set the mail.imap.usesocketchannels property in the Session