Run folderlist.java with Gmail SSL IMAP

Q

How to run folderlist.java in javamail1_4_7.zip with Gmail using SSL IMAP protocol? I have a valid Gmail email account.

✍: FYIcenter.com

A

folderlist.java in javamail1_4_7.zip can be used to retrieve mail folder information from Gmail mail server using SSL IMAP protocol. Here is an execution session of folderlist.java:

fyicenter>cd \local\javamail-1.4.7\demo

local\javamail-1.4.7\demo>java -version 
java version "1.8.0_45"

local\javamail-1.4.7\demo>javac -cp ..\mail.jar folderlist.java

local\javamail-1.4.7\demo>java -cp .;..\mail.jar folderlist 
   -D -L imaps://john:password@imap.gmail.com

DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap
.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from 71.174.32.174 62mb186219888ybr
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-
1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER
AUTH=XOAUTH
A0 OK Thats all she wrote! 62mb186219888ybr
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: PLAIN-CLIENTTOKEN
DEBUG IMAPS: AUTH: OAUTHBEARER
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: protocolConnect login, host=imap.gmail.com, user=john, password=<no
n-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A1 NO [AUTHENTICATIONFAILED] Inv
alid credentials (Failure)
Exception in thread "main" javax.mail.AuthenticationFailedException: [AUTHENTICA
TIONFAILED] Invalid credentials (Failure)
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661)
        at javax.mail.Service.connect(Service.java:295)
        at javax.mail.Service.connect(Service.java:176)
        at javax.mail.Service.connect(Service.java:125)
        at folderlist.main(folderlist.java:107)

The output shows that:

  • The mail.jar contains JavaMail API classes like javax.mail.Service.
  • The mail.jar contains IMAP implementation classes like com.sun.mail.imap.IMAPStore.protocolConnect.
  • JavaMail 1.4.7 supports SSL IMAP protocol.
  • imap.gmail.com server supports SSL IMAP protocol on port 993.
  • The authentication failed exception is expected, because the account name and password are invalid. If you provide your real gmail account name and password, you will get correct result.

Back to FAQ for JavaMail API and Implementations.

2016-01-22, 1067👍, 0💬