Read mails again and again from gmail using JavaMail Api in java

If you want to get All Emails every time, IMAP sever will be best for it.

You can change the mail server to

IMAP.gmail.com

and the port will be 993 (considering you are using gmail account).

The Link sidgate provided will be best example for you.


Gmail has user settings for how pop3 mail requests are handled. I was having this same issue, and ended up checking out this page: https://javaee.github.io/javamail/FAQ#gmailsettings.

To see all email every time, you need to enable the flag (in the settings page): Enable POP for all mail (even mail that's already been downloaded)

Did the trick for me. Hope that helps.

Tags:

Java

Gmail Api