Hi Raj,
Here is the code that can be useful to you.
Just Imagine that my database name is email and the table name is passwd. You just prepare an html file asking the user to enter his/her email address.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import sun.net.smtp.*;
public class authenticate extends HttpServlet
{
private Connection con;
private Statement stat;
private SmtpClient client;
public void init(ServletConfig config) throws ServletException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc
dbc:email");
client=new SmtpClient("MAIL_HOST")//replace
//MAIL_HOST with proper host.
}
catch(ClassNotFoundException cnfe)
{
getServletContext().log(cnfe,"Could not found class");
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String uaddr=req.getParameter("uaddress");//uaddress=user
//email address
String sql="select password from passwd";//password is
//field name and passwd is table name.
try
{
ResultSet r=stat.executeQuery(sql);
if(r!=null)
{
r.next();
String p=r.getString(1);
if(p!=null)
{
client.from("team@urname.com");
client.to(uaddr);
PrintStream ps=client.startMessage();
ps.println("From: "+"team@urname.com");
ps.println("To: "+uaddr);
ps.println("Subject: Your Password");
ps.println("Dear user here is ur password "+p);
client.closeServer();
}
}
}
catch(SQLException sqe)
{
getServletContext().log(sqe,sqe.toString());
}
catch(Exception e)
{
getServletContext().log(e,"Exception occured");
}
}
public void destroy()
{
try
{
if(con!=null)
{
con=null;
}
}
catch(SQLException sqe)
{
getServletContext().log(sqe,sqe.toString());
}
}
}
Raj i dint tested this code, but i am sure that it works fine, if anything goes wrong please intimate me.
I hope this code will be useful to you.
Loke.
[This message has been edited by lokesh reddy (edited October 27, 2000).]