How do I get rid of unused connections? Doing something like checking for the existance of an IMAP folder leaves the connection open.

John Zukowski

You can set the connection pool timeout property (mail.imap.connectionpooltimeout for imap). Then... according to JavaMail architect Bill Shannon:

Because JavaMail doesn't use a separate thread to manage the timeout, it only checks for connections to timeout when you do something with the Store. Adding a call to store.isConnected() after the timeout should trigger the timeout/disconnect.