Library for IMAP IDLE

综合编程 2018-02-02

I'm looking for a Java library that helps me using IMAP and preferably IDLE.

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

So far I've looked at:

Apache Commons Imap
but it doesn't seem to implement IDLE.

but it is not sufficiently documented (I might be able to work it out but I'm not sure my successors will be as pleased).

, their IMAPFolder seems like a good choice but I'm short on time and writing a stable library for it will take time.

is a $199 library, it's a bit pricy (I know, free and good reliable code is always ease to come by 🙂 Plus, I'm not sure it handles IDLE.

I could go for a solution that polls the inbox if it's documented and stable.

I'd appreciate some example code, a library or a push in the right direction.

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

I haven't worked with any of the libraries that you mentioned except Javamail, but I can vouch for it. I had to write an application that polls an exchange server and parses all the new mail in an inbox. Here is a snippit of the code used in that project. I did all the polling in-app, so I wasn't looking into push notifications from server or anything. I know this isn't precisely what you were asking for, but I hope it is a step in the right direction.

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

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("", "*");

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

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

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

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

            for (int i = messages.length -1; i>=0; i--) {
                messages[i].setFlag(Flags.Flag.SEEN, true);
            // Close connection
        catch(Exception e){
Hello, buddy!

责编内容by:Hello, buddy! (源链)。感谢您的支持!


Sending an email in Android version using the Java... I have referred to previous answers to similar question of mine but it gives ...
Sending Mail Using the JavaMail API for Gmail I was recently trying to experiment with an automation framework where I wanted ...
使用JavaMail发送邮件 使用JavaMail的API发送邮件~! 1 import org.apache.commons.collections.Collection...
Sending an email in Android version using the Java... I have referred to previous answers to similar question of mine but it gives ...