I want to make an application which connects to my mail server(say rediff for example) takes a user id and password and downloads all the mails in the INBOX.
I have a program but it always give unknown host error.Can anyone suggest how to go about it and what all things i will be needing.
Thanks Himanshu
Jeremy Wilson
Ranch Hand
Joined: Feb 18, 2003
Posts: 166
posted
0
Here is code I used Store store=null; Folder folder=null; try {
Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props, null); store = session.getStore("pop3"); store.connect(popServer, popUser, popPassword); folder = store.getDefaultFolder(); if (folder == null) throw new Exception("No default folder"); folder = folder.getFolder("INBOX"); if (folder == null) throw new Exception("No POP3 INBOX"); folder.open(Folder.READ_ONLY); Message[] msgs = folder.getMessages(); for (int msgNum = 0; msgNum < msgs.length; msgNum++) { System.out.println(msgs[msgNum].getSubject()); }
} catch (Exception ex) { ex.printStackTrace(); } finally { // -- Close down nicely -- try { if (folder!=null) folder.close(false); if (store!=null) store.close(); } catch (Exception ex2) {ex2.printStackTrace();} }