How can receive emails in Java based system preferably with spring?
Spring integration was designed to solve these kind of problems. In particular it has e-mail receiving adapters. Here is an IMAP example from the documentation:
<mail:inbound-channel-adapter id="imapAdapter"
store-uri="imaps://[username]:[password]@imap.gmail.com/INBOX"
java-mail-properties="javaMailProperties"
channel="recieveChannel"
should-delete-messages="true"
should-mark-messages-as-read="true"
auto-startup="true">
<int:poller max-messages-per-poll="1" fixed-rate="5000"/>
</mail:inbound-channel-adapter>
POP3 and IMAP are not protocols that receive email. They go out and fetch it from a server.
The official JavaMail API
provides a platform-independent and protocol-independent framework to build mail and messaging applications.
Take a look!