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.

List Information about folder

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://[email protected]/inbox
Has New Messages
Total Messages:  7
New Messages:  0
Unread Messages: 7

Download code