Email – does JavaMail support server push?
Does JavaMail support push notification of new e-mail through the server?
If so, where is the document? If not, is there a library you can do?
Solution
You should use the idle function of imapfolder to issue idle commands to the server It will then listen to events such as new messages or deleted messages (see the IMAP specification to see what the message looks like) And when some e - mails in the mailbox change, you should use messagecountlistener to execute the code
The idle function of IMAP is to imitate the "push" function
http://java.sun.com/products/javamail/javadocs/javax/mail/event/MessageCountListener.html http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/IMAPFolder.html
Sorry, I haven't released any code showing how to use it I don't want to waste my time, because if you search this thing, there are many easily available examples on the Internet
However, it should be warned in advance that this method will not work on multiple IMAP accounts due to idle command blocking Unless you want them all on different threads (bad idea)