Java Reference
In-Depth Information
try{
// -- Get the default session --
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
// -- Get a POP3 message store, and connect to it --
store = session.getStore("pop3");
store.connect(server, username, password);
// -- Get the default folder --
folder = store.getDefaultFolder();
if (folder == null) throw new Exception("No default folder");
// -- Get its INBOX --
folder = folder.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");
// -- Open the folder for read only --
folder.open(Folder.READ_ONLY);
// -- Get the message wrappers and process them --
Message[] msgs = folder.getMessages();
int msgNum = msgs.length;
while(processMessage(msgs[--msgNum]));
}
catch (Exception e){
e.printStackTrace();
}
finally{
try{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public static boolean processMessage(Message message){
Calendar today = Calendar.getInstance();
try{
Search WWH ::




Custom Search