Pergunta

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.

JavaPushMail 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).

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

Chilkatsoft 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.

Foi útil?

Solução 2

I went ahead and used Javamail. Just think it's strange no decent wrapper/client has been written for it yet. Well well, can't have it all. Thanks for the answer, Conor Sherman.

Outras dicas

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.*
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){
        }
    }
}

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

https://github.com/MailCore/mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top