import Java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
/**
* Demonstrate POP mail using JavaMail. Requires mail.jar activation.jar
* Sample run: java -cp .;mail.jar;activation.jar PopMail
**/
public class PopMail
{
public static void main(String args[]) throws Exception
{
String pop3Host="myhost.com", popUser="john", popPassWord="letmein";
Session session = Session.getDefaultInstance(System.getProperties(), null);
Store store = session.getStore("pop3");
store.connect(pop3Host, -1, popUser, popPassword);
// Open the default folder
Folder folder = store.getDefaultFolder();
if (folder == null)
throw new NullPointerException("No default mail folder");
folder = folder.getFolder("INBOX");
if (folder == null)
throw new NullPointerException("Unable to get folder: " + folder);
// Get message count
folder.open(Folder.READ_WRITE);
int totalMessages = folder.getMessageCount();
if (totalMessages == 0)
{
System.out.println("No messages found in inbox");
folder.close(false);