Library for IMAP IDLE

I am looking for a Java library that helps me use IMAP and preferably IDLE.

I need to write a Java application that is notified and receives a new email using SSL. The application will check the inbox of the account hosted in hMailServer.

So far I watched:

Apache Commons Imap , but does not seem to implement IDLE.

JavaPushMail , but it's not well documented (I could handle this, but I'm not sure if my successors will be happy).

Javamail , their IMAPFolder seems to be a good choice, but I don’t have time to write a stable library, because it will take time.

Chilkatsoft is a $ 199 library, it's a little expensive (I know, free and good reliable code is always easy to come :) Plus, I'm not sure if it handles IDLE.

I could find a solution that checks the contents of the mailbox if it is documented and stable.

I would appreciate some sample code, a library, or clicking in the right direction.

Sorry for all the "I" and thanks in advance.

+5
source share
3 answers

I went ahead and used Javamail . Think it's weird, a decent wrapper / client has not yet been written for this. Well, that’s not all. Thanks for the answer, Conor Sherman.

+2
source

, Javamail, . , "". , . , push- - . , , , , .

import java.util.Properties;
import javax.mail.*
import javax.mail.search.FlagTerm;


public class Driver {
    public static void main(String[] args){
        // Create properties (disable security checks on server)
        Properties props = new Properties();
        props.put("mail.imaps.ssl.checkserveridentity", "false");
        props.put("mail.imaps.ssl.trust", "*");

        // Get session
        Session session = Session.getDefaultInstance(props, null);

        try{
            // Get the store
            Store store = session.getStore("imaps");
            store.connect("servername", "username", "password");

            //connection configuration
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_WRITE);

            //get all unread messages in the inbox
            FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); 
            Message[] messages = folder.search(ft);

            for (int i = messages.length -1; i>=0; i--) {
                messages[i].setFlag(Flags.Flag.SEEN, true);
            }
            // Close connection 
            folder.close(false);
            store.close();
        }
        catch(Exception e){
        }
    }
}
+2

I have not used it myself, but this library looks good:

https://github.com/MailCore/mailcore2

MailCore 2 provides a simple and asynchronous API for working with IMAP, POP, and SMTP email protocols. The API has been redesigned from scratch.

-1
source

All Articles