Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-28-2011, 09:41 AM
Starter Member
 
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 04-28-2011, 12:36 PM
Outstanding Member
 
Posts: 717
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
Reply With Quote
  #3 (permalink)  
Old 04-29-2011, 03:14 AM
Starter Member
 
Posts: 2
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.