Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I need to check for email in my J2EE app, please help??  RSS feed

 
Derick Potgieter
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need to check for email in my program on a regular basis.
The idea is that a user can send a html email to the system and then i can extract the information and send a reply back.

Can anyone give me some help regarding this problem.
Thanks
Derick
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Mail API is what you need.
 
Derick Potgieter
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i dont know when a use is sending me an email. Should i be using a Message driven bean, and then when there is a email respond to that request.

The problem is i`m not sure how to set up the queue`s or how to actually use them??

I`m useing jboss 4.0.1 and EJB2.1
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a process which occasionally checks a particular user's POP3 INBOX. You could have an application which is permanently connected to the POP3 server and looking for new messages, and firing off a JMS message to a queue for some listener (possibly an MDB) to respond to.

Personally, I wouldn't involve JMS in this - what benefits does it give you in this instance? A better idea would be some sort of scheduled timer (such as java.util.Timer), which periodically reads an INBOX and generates SMTP messages appropriately.
 
Derick Potgieter
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for sounding a bit lost,

but could you mabe give me some code in this regards.

Wount this keep one of my beans then occupied the whole time, is`nt that the main reason to use MDB??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but could you mabe give me some code in this regards.

Ah, no - not in the spirit of this site I'm afraid. I will try to give you as many pointers as I can though.

There is a useful "how to" with regards to Java Mail at Sun. Assuming you understand POP3 and SMTP (just enough to know how to use it - you don't need to know the RFCs of by heart!) it should make reasonable sense. If you don't, then I'm afraid you'll have to learn.

java.util.Timer is your "scheduled job", so to speak. It would just be a thread which performs some task as a defined interval. java.util.TimerTask is the task this Timer performs. It has a run method which does whatever work you need. Read the JavaDocs for these two classes, they are pretty simple.

Yes this would keep one of your beans occupied all the time (if you did it through a bean - which of course would break the J2EE rules: a Timer is a seperate thread, and you can't start new threads from an EJB). But why use a bean at all? What's wrong with writing a little seperate app. which just handles the email stuff? Do you have a requirement to access business funtionallity available through your EJBs? If so - couldn't your seperate email processing app. not just access the ejb service methods as any other client would? Emails == asynchronous, so response time is much less important.
 
Derick Potgieter
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks...

I`m currencly reading up on the timer service and it seems like it will work for me.

But

Why cant i use a MDB to read a queue and everytime there is a message process it. Is it just that the complexity of the app gets to much??

I do believe that the timer service will work easier and save on time, but is it really the correct way?? Sorry very new to these two subjects..

Thanks for the help
Derick
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why cant i use a MDB to read a queue and everytime there is a message process it. Is it just that the complexity of the app gets to much??

There is nothing to stop you doing this. What you need to consider, however, is how messages get on that queue which the MDB responds to. You can't use SMTP to send a message to a JMS queue directly, so something else would need to be reading incoming mails and sending them to the queue. If you have this anyway, why use a queue? Think of the POP3 INBOX as a queue in its own right. POP3 servers usually work by holding incoming message in a mailbox till some client reads them. Sounds queue-like doesn't it?

So what does JMS add? Asynchronicity? Well, email is asynchronous anyway. A performance improvement? Its more likey to cause extra work for your app. server, since now it has to worry about managing a queue. Multi-threading? If you need this (and its unlikely that you will) just write your mail processing app. as a multithreaded app. Security? This is going to run on the server (i.e. no direct client access), and SMTP is inherently insecure anyway.

You have to think, if you want to use one of the pieces of container-provided enterprise functionality why you need it. If you don't have a compelling reason, then an enterprise solution where a simple one would do is always overkill.
 
Derick Potgieter
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,

I`m actually understanding it now....

Best Regards
Derick
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!