aspose file tools*
The moose likes Java in General and the fly likes Java Mail listener not being invoked 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 » Java in General
Bookmark "Java Mail listener not being invoked" Watch "Java Mail listener not being invoked" New topic
Author

Java Mail listener not being invoked

NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi
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

NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi
Is there no one who could help me on this...???
I'm stuck up here...I am in real need RANCHERS.........


Thanks
NarayanaRao.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Please Ease Up. When someone who knows the answer comes along, he/she will surely post it. But it's not impossible that nobody simply has an answer for you - we are not all-knowing here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi 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
NarayanaRao.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42911
    
  68
My first post in this recent topic explains why the flags don't work how you expect them to work.
NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi Dittmer
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?

Thanks
NarayanaRao.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42911
    
  68
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.
NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi Dittmer
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.

Thanks
NarayanaRao.
Tanay Talukdar
Greenhorn

Joined: Jan 07, 2012
Posts: 1
Hi Narayana,

I am facing a problem regarding the java mail listener. How you have configured the listener and used the message id to listen to the new mails.

Regards,
Tanay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail listener not being invoked