aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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
Author

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.

Thanks
Himanshu
Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
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();}
}


Jeremy Wilson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve mails from POP 3 server