Using JavaMail to Search GMail With IMAP

Enable IMAP in GMail Log into your GMail account and go to Settings Switch to tab “Forwarding and POP/IMAP” Select Enable IMAP Set Folder size limits to Limit IMAP folders to contain no more than this many messages 1,000 Less secure app access Go to Turn on Allow less secure apps if this is not turned on, we will get following exception javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure) at com.