Here's a quick hack I did to check your email every 10 minutes. Just plug
your pop-server name, your userID and password.
You must download JavaMail and include in CLASSPATH
CheckMyEMail.java

/*
 * CheckMyEMail.java
 *
 * Created on July 10, 2002, 9:00 PM
 * @author Ramon Gonzalez
 */

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

public class CheckMyEmail {

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

        String pop3Host = "pop-server.tampabay.rr.com"; //pop host name
        String user = "userid"; //pop user Id
        String password = "password"; //POP Password
        int checkPeriod = 10; //checks inbox every x minutes

        CheckMyEmail checkMyEmail = new CheckMyEmail();

        while (true) { //loops every x minutes forever
            checkMyEmail.process(pop3Host, user, password);
            Thread.sleep(checkPeriod*1000*60); //sleep every x minutes
        }
    }

    /**  process() checks for new messages
     */

    public void process(String pop3Host, String user, String password)
    throws Exception {

        String INBOX = "INBOX";
        String POP_MAIL="pop3";

        try {

            // Get a Session object
            Properties sysProperties = System.getProperties();
            Session session = Session.getDefaultInstance(sysProperties,
null);
            session.setDebug(false); //set to true for session debug

            Store store = session.getStore(POP_MAIL);
            store.connect(pop3Host, -1, user, password);

            // 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(folder + " is empty"); //use to see if
empty
            } else {
                System.out.println("You have Mail! There are " +
totalMessages+ " messages in your " + folder + " folder.");
            }

            folder.close(false);
            store.close();
            return;

        } catch (Exception e){
            System.out.println("Exception while checking email count.");
        }
    }
}


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.368 / Virus Database: 204 - Release Date: 5/29/2002


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to