0

Possible Duplicate:
how to send an email from jsp/servlet?

is it possible to send email from a mail id to other mail ids using a jsp page? I have developed a complaint management System where user can submit their complaints by giving the details and then a complaint number is generated. But I need to ensure that user gives a proper email Id.

So I want to send the complaint number to the email ids that the user puts in the form. I don't have any idea how to send mail to the id using jsp, I have googled about that but unfortunately didnot find any helpful solution. I am using jsp and java for developing the application.

Would really appreciate if someone could help me and I apologies for poor writing.

Community
  • 1
  • 1
Biswajit das
  • 51
  • 1
  • 2
  • 7

1 Answers1

0

Try this:

<%@ taglib uri="http://jakarta.apache.org/taglibs/mailer-1.1" prefix="mt" %>
<mt:mail session="java:/comp/env/mail/Session" to="foo@home.net" from="registration@mydomain.de" subject="Registration Confirmation">
    <mt:message type="html"><h1>Perfect</h1>Super</mt:message>
    <mt:send/>
</mt:mail>

Therefore your /META-INF/context.xml must contains:

<?xml version='1.0' encoding='utf-8'?>
<Context>
  <Resource name="mail/Session" 
     auth="Container"
     type="javax.mail.Session"
     username="webmaster@mydomain.de"
     password="password"
     mail.debug="true"
     mail.user="webmaster@mydomain.de"
     mail.from="registration@mydomain.de"
     mail.transport.protocol="smtp"
     mail.smtp.host="smtp.strato.de"
     mail.smtp.auth="true"/>
</Context>

And /WEB-INF/web.xml must contains:

...
    <resource-ref>
       <res-ref-name>mail/Session</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web>

Note: The context.xml will be copied into the jboss-server if not exists. This is the way, the application-server differs the configurations of environments (live,test,staging).

Note: You need mail.jar, mailer-1.1.jar and mail-1.4.4.jar in your tomcat/lib-directory (because of the context.xml will be available even if the application is no longer deployed.)

Grim
  • 1,938
  • 10
  • 56
  • 123