File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes How  to retrieve mails from POP 3 server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How  to retrieve mails from POP 3 server " Watch "How  to retrieve mails from POP 3 server " New topic

How to retrieve mails from POP 3 server

Himanshu Bisht
Ranch Hand

Joined: Aug 27, 2004
Posts: 96
Hi all!!

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.

Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
Here is code I used
Store store=null;
Folder folder=null;

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");;
Message[] msgs = folder.getMessages();
for (int msgNum = 0; msgNum < msgs.length; msgNum++)

catch (Exception ex)
// -- Close down nicely --
if (folder!=null) folder.close(false);
if (store!=null) store.close();
catch (Exception ex2) {ex2.printStackTrace();}

Jeremy Wilson
I agree. Here's the link:
subject: How to retrieve mails from POP 3 server
It's not a secret anymore!