• 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

regarding auto mail system

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to incorporate an autoreply email system in my web based application made in jsp and servlets running on apache tomcat. Now in it when a user sends a mail with the code as subject, the application reads it and queries the database and has to send the information which on web is generated in jsp. The problem is
(1) At the moment, when I load the servlet in web browser then only the mails are received. I want to know whether anything can be done where as soon as the mail is received, the servlet reads it and sends the reply.
(2) How do I send the page on which information is there
regards
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think after much typing and erasing on my part, I finally get what you're wanting... you want two interfaces to a web app. One in the normal fashion, where someone can make requests and receive information. They click links, say for a product brochure. The request might be something like: "http://www.myfoo.com/prods/show?pid=345" which would show us product number 345.

And in addition, you want to enable someone to access this same page of information, by emailing the system like so:
to: autoresponder@myfoo.com
subject: 345

If this is so, then I think there might be a gap in your understanding of web apps and email, and I apologize in advance if I'm not correct.

1) At the moment, when I load the servlet in web browser then only the mails are received.

How is a servlet "receiving" email? What's sending it?

Your web app listens on port 80 for http requests. The email is being sent to port 25, and an email server is listening to that port. The email server doesn't even have to be on the same physical machine as your web server.. they have nothing to do with one another.

So you need to bridge the two.

In order for your webapp to 'receive' this email, you need to use JavaMail, and have a background process check a specified mailbox (in our example, the 'autoresponder' inbox) every 'n' seconds for emails. Upon finding an email in the inbox, it needs to retrieve it, parse out the subject (all very easy, through JavaMail) and after that, do its processing and database querying based on the code in the subject.

As for 2)... Again, you use JavaMail. You can have your background process 'reply' to the email it is currently processing, and using various methods of that API, send a plain-text or HTML response to the email.

How to actually "get" the JSP page that normally displays the page when a link is clicked, so that you can place that HTML output into an email? You can use an java.net.HttpUrlConnection to emulate an actual request.
 
gaurav chaudhary
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Mike. I have already implemented java mail and receiving the mails and can also send the replies but only when I call the servlet from my browser. I want it to be done automatically something like Apache can call my servlet to be executed and I donot have to call it explicitly from my browser.
One more thing I want to do if it can be incorporated is that whenever a new mail is received then only the servlet is invoked and it does not check the mail server every second when there is no received mail.
thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic