Does JavaMail support server-push?

后端 未结 2 1697
清酒与你
清酒与你 2020-12-14 22:22

Does JavaMail support notification of new emails through server-push?

If yes, where is the documentation for that? If no, is there a library that can do it?

相关标签:
2条回答
  • 2020-12-14 22:30

    You should be using IMAPFolder's idle function to issue the idle command to the server. That will then listen for events, such as a new mail or deleted mail. (See the IMAP spec to see what the messages look like). And you should be using a MessageCountListener to execute code when a number of emails in the mailbox change.

    IMAP's idle function is exactly meant to imitate "push" functionality.

    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 didn't post any code that shows how this is used. I didn't want to waste my time since there are many readily available examples on the internet if you search for this stuff.

    But be forewarned, this method won't work for more than one IMAP account since the idle command blocks. Unless you want them all on different threads (bad idea).

    0 讨论(0)
  • 2020-12-14 22:39

    A Store event listens for notifications issued by your backend store:

    http://java.sun.com/products/javamail/javadocs/javax/mail/event/StoreEvent.html

    But in my experience the java mail docs are so thin in places, that the best way of finding out what is going on, is to debug through the process yourself.

    This is a great allround resource as well; the JavaMail FAQ :

    http://www.oracle.com/technetwork/java/faq-135477.html

    0 讨论(0)
提交回复
热议问题