Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Other JSE/JEE APIs and the fly likes Retrieving mails using Java Mail API 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 "Retrieving mails using Java Mail API" Watch "Retrieving mails using Java Mail API" New topic

Retrieving mails using Java Mail API

Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
In my project,i am retrieving mails from a particular email id.
I am able to retrieve the latest mails and save it in a folder in my system.
The problem is whenever i run the program eventhough the most recently received mail in inbox is retrieved and saved,again it is retrieving the same one and saving it in the same folder(not repeating).

I tried to check the newmessages in the inbox using the folder.hasNewMessage() method in java mail api,but the method is returning false only regardless new mail is there in inbox or not.
I want to read the unread messages only.Dont want to retrieve the already read mails.
I got the mail retrieving code from the below site.(sorry not posting the code because it is so long and having 4 classes),39024620,39228060,00.htm

Can anyone tell me how to read unread mails in the inbox?

Thanks a lot
jack wenttohill

Joined: Apr 26, 2009
Posts: 9
Message[] unreadMessages = FlagTerm(new Flags(Flags.Flag.SEEN), false));
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2851

"jack wenttohill " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.

|Asking Good Questions|
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Are you using POP or IMAP? If it's POP, then this probably won't work because it relies on Flags; see my response in this topic
I agree. Here's the link:
subject: Retrieving mails using Java Mail API
It's not a secret anymore!