I tried to implement a java mail listener using the MessageCountListener of java mail API.
Program is running but the listener is not being invoked when a new mail is arrived.
I tried to listen to a mail, and if the mail is a desired one, I wanted to read the message and insert the message into a database.
Please help me on this.I will be very thankfu..
Below is the code
Joined: Jan 29, 2008
Is there no one who could help me on this...???
I'm stuck up here...I am in real need RANCHERS.........
I found a solution to the above scenario.
I got a way to check the messages in the INBOX in regular intervals of time.
But the problem is, I am not able to find if a message is recent message and if a message is an UnRead message.
Java mail api provides Flags for each mail. I tried two flags(RECENT and SEEN) to identify a new mail. But they did not behave as they are supposed to. I could not understand why. Below is the code snippet.
Though the message is a recent message, the control is not going into the IF loop. Does this operation need any permissions from the Mail Server..?
Briefly, I ask.........> How to identify a new mail?
Thanks for the reply. Now no Flags are supported.
So I would like to use the Received date of the mail and then proceed. But I am not able to get the received date too from the mail. I got 'null' when I tried to access mail.getReceivedDate().
Will there be no received date for a mail?
Joined: Mar 22, 2005
I'm not sure under what circumstances the received date would or would not be set. But you could always get all "Received" headers through the getHeader(String) method. Or it may be easier to get the "Sent" header of which there should be only one, and which contains only a date (as opposed to "Received" headers, which contain other information as well). That's also available through the getSentDate() method, but I guess it might be null, too.
Joined: Jan 29, 2008
Thanks for the reply. I am done with the job now.
sentdate is not null. getSentDate() is returning a Date but that is the sender's date and time.
As you suggested in your previous reply, I used the Message-ID header and proceeded with my job.
Thanks a lot for the suggestion. It is toooooo good to have people like you on JavaRanch.