• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Mail listener not being invoked

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Is there no one who could help me on this...???
I'm stuck up here...I am in real need RANCHERS.........


Thanks
NarayanaRao.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
NarayanaRao Konakalla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first post in this recent topic explains why the flags don't work how you expect them to work.
 
NarayanaRao Konakalla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using IMAP protocol, this works well

reply
    Bookmark Topic Watch Topic
  • New Topic