Home Javamail List Information about folder
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

List Information about folder

Advertisement
This Example shows you how to show folder information. In this code we have used method of Folder class to retrieve information about folder where mail is stored.

List Information about folder

     

This Example shows you how to show folder information. In this code we have used method of Folder class to retrieve information about folder where mail is stored. Some of these methods are....

getName()is an abstract method and returns name of the folder of String type.
getFullName()returns the String type full name of folder
getURLName()returns the URL name representing this folder of URLName type.
getMessageCount()returns an integer value that represent total number of messages in this folder.
getNewMessageCount()returns an integer value that represent total number of new messages in this folder.
getUnreadMessageCount()returns an integer value that represent total number of unread messages in this folder.

FolderInfo.java


import java.util.*;
import javax.mail.*;

public class FolderInfo {

  public static void main(String args[]) throws Exception {

  Properties properties = System.getProperties();

  Session session = Session.getDefaultInstance(properties);
  Store store = session.getStore("pop3");

  store.connect("192.168.10.205", "test", "test");

  Folder folder = store.getFolder("inbox");
  folder.open(Folder.READ_ONLY);

  System.out.println("Name:  " + folder.getName());
  System.out.println("Full Name: " + folder.getFullName());
  System.out.println("URL: " + folder.getURLName());

  System.out.println("Has New Messages");
  System.out.println("Total Messages:  " + folder.getMessageCount());
  System.out.println("New Messages:  " + folder.getNewMessageCount());
  System.out.println("Unread Messages: " + folder.getUnreadMessageCount());
  }
} 

Output:

Name:  inbox
Full Name: inbox
URL: pop3://test@192.168.10.205/inbox
Has New Messages
Total Messages:  7
New Messages:  0
Unread Messages: 7

Download code

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 19, 2008

Ask Questions?    Discuss: List Information about folder  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com