Search code examples
javaemailjodd

Setting timeout for Jodd Imap or Pop3


I'm using Jodd Email library to send and receive emails. With Jodd SmtpServer I can set connection timeout. I have tried to read the documentation but I have not found anything. I would like to set a timeout with Imap or Pop3.


Solution

  • Just extend the e.g. ImapServer class and override the createSessionProperties method like this:

    public class MyImapServer extend ImapServer {
        ...
        protected Properties createSessionProperties() {
            Properties props = super.createSessionProperties()
            props.setProperty("mail.imap.connectiontimeout", 123);
            return props;
        }
    }
    

    With migration to Java8 it's going to be even easier to do this, as we will provide the session properties with some fluent interface.

    Timeout is rather commonly used, we might add direct support for it as well.