Results 1 to 3 of 3

Thread: Retrieve a email using JavaMail API

  1. #1
    Shashwat is offline Starter Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    3

    Default Retrieve a email using JavaMail API

    Hi

    I am need to monitor a zimbra email account using JavaMail API and do some processing when new mail is recieved. I am able to see the count of Inbox folder's messages.
    But when count is changed then MessageCountEvent is not thrown.

    Code : ---------------------------------------------

    public void retrieveMail(String popServer, String popUser, String popPassword) {
    final String FOLDER_TO_LOOK = "Inbox";
    Store store = null;
    Folder folder = null;
    try {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    store = session.getStore("pop3");
    store.connect(popServer, popUser, popPassword);

    folder = store.getFolder(FOLDER_TO_LOOK);
    if (folder == null) {
    throw new Exception("No POP3 INBOX");
    }

    folder.open(Folder.READ_ONLY);
    System.out.println("Class MailRetriever : Message count in folder is " + folder.getMessageCount());
    folder.addMessageCountListener(new MessageCountListener() {
    final String SUBJECT_SHOULD_BE = "Process it from Email Server";
    @Override
    public void messagesAdded(MessageCountEvent event) {
    System.out.println("Post class mail retiver");
    try {
    Message[] messages = event.getMessages();
    System.out.println("Got " + messages.length + " new messages");
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }
    @Override
    public void messagesRemoved(MessageCountEvent event) {
    System.out.println("Class : MyMessageCountListener : Message count in folder is " + event.getMessages().length);
    }
    });
    } catch (Exception ex) {
    ex.printStackTrace();
    } finally {
    try {
    if (folder != null) folder.close(false);
    if (store != null) store.close();
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }
    }

    --------------------------------------------------------------

    Thanks
    Shashwat Anand
    sanand@vmware.com
    shashwat.work@gmail.com

  2. #2
    Krishopper is offline Dedicated Member
    Join Date
    Dec 2006
    Location
    Minneapolis MN
    Posts
    775
    Rep Power
    9

    Default

    POP3 doesn't support events, so the JavaMail API is the one continuing to look for new messages. You may have better luck posting on their forums.

    I did find this however, it may help you: Java Mail listener not being invoked (Java in General forum at JavaRanch)
    01 Networks, LLC / Cybernetik.net
    Zimbra NE and OSS Cloud Hosting
    Shared Web Hosting
    Consulting Services

  3. #3
    Shashwat is offline Starter Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    3

    Default

    Quote Originally Posted by Krishopper View Post
    POP3 doesn't support events, so the JavaMail API is the one continuing to look for new messages. You may have better luck posting on their forums.

    I did find this however, it may help you: Java Mail listener not being invoked (Java in General forum at JavaRanch)

    Thanks Krishopper. The link given by you was very helpful to solve my problem.

    Thanks
    Shashwat

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Email API
    By bruder in forum Developers
    Replies: 0
    Last Post: 10-03-2010, 02:30 AM
  2. need advice on configuring zimbra to work with fax server
    By pheonix1t in forum Administrators
    Replies: 0
    Last Post: 07-11-2007, 07:46 PM
  3. upgrade to 4.0.3 antispam does'nt work
    By lucanannipieri in forum Administrators
    Replies: 14
    Last Post: 11-07-2006, 03:56 AM
  4. New installation, but can not retrieve email
    By RomanHoliday in forum Administrators
    Replies: 5
    Last Post: 01-05-2006, 09:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •