folderlist Sample Program with JavaMail 1.5.4


What is the in I downloaded it together with javax.mail-1.5.4.jar.


A in is a sample program that lists information about the folders in an email account on a mail server.

If you downloaded and installed together with javax.mail-1.5.4.jar, is located at \local\javamail-1.5.4\javamail-samples\ Below is the usage description of

  This program lists information about the folders in a Store.

   java folderlist -L <url> -T <protocol> -H <host> -U <user>
        -P <passwd> [-R <root>] [-r] [-v] [-D] <pattern>

   -L <url>  : URL of the Store. The URL should include
        the password as well (if needed).
        Example: "imap://"
   -T <protocol> : store protocol (Ex: "imap")
   -H <host> : hostname of store.
   -U <user> : username (if needed)
   -P <passwd>   : password (if needed)
   -R <root> : root of the folder hierarchy. This is optional. If
      not present, listing starts from the default folder.
   -r       : list recursively - folder and all subfolders.
   -v       : verbose - show more info about each folder.
   -D       : Turn on session debugging
   <pattern>  : folders that match this pattern are listed. Use "*"
      as wildcard to match everything.

Here is an execution session of

fyicenter>cd \local\javamail-1.5.4\javamail-samples

local\javamail-1.5.4\javamail-samples>java -version
java version "1.8.0_45"

local\javamail-1.5.4\javamail-samples>javac -cp .;..\javax.mail-1.5.4.jar

local\javamail-1.5.4\javamail-samples>java -cp .;..\javax.mail-1.5.4.jar
   folderlist -D -L imap://

DEBUG: setDebug: JavaMail version 1.5.4
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: trying to connect to host "", port 143, isSSL false
Exception in thread "main" com.sun.mail.util.MailConnectException: Couldn't conn
ect to host, port:, 143; timeout -1;
  nested exception is: Connection timed out: connect
        at com.sun.mail.imap.IMAPStore.protocolConnect(
        at javax.mail.Service.connect(
        at javax.mail.Service.connect(
        at javax.mail.Service.connect(
        at folderlist.main(

The output shows that:

  • The javax.mail-1.5.4.jar contains JavaMail API classes like javax.mail.Service.
  • The javax.mail-1.5.4.jar contains IMAP implementation classes like com.sun.mail.imap.IMAPStore.protocolConnect.
  • The connection time out exception is expected, because is not valid mail server.


Run 1.5.4 with Gmail SSL IMAP

Download and Install

Download and Install JavaMail Library

⇑⇑ FAQ for JavaMail

2016-01-11, 2603🔥, 0💬