Posted By:
shruti_babbar
Posted On:
Tuesday, April 29, 2008 03:40 AM
MailServlet i am writing the below code for sending mail and error is coming in one line. i think i am not setting the ISP correct can anyone help me out in this its really impt public class MailServlet1 extends HttpServlet { public void init(ServletConfig config) throws ServletException { super.init(config); } public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { String host="vsnl.yahoo.com"; String to=req.getParameter("to"); String from=req.getParameter("from"); String subject=req.getParameter("subject"); String messageText=req.getPa
More>>
MailServlet
i am writing the below code for sending mail and error is coming in one line. i think i am not setting the ISP correct can anyone help me out in this its really impt
public class MailServlet1 extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String host="vsnl.yahoo.com";
String to=req.getParameter("to");
String from=req.getParameter("from");
String subject=req.getParameter("subject");
String messageText=req.getParameter("body");
boolean sessionDebug=false;
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("
");
out.println("
");
Properties props=System.getProperties();
props.put("mail.smtp.host",host);
props.put("mail.transport.protocol","smtp");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg=new MimeMessage(mailSession);
try
{
msg.setFrom(new InternetAddress(from));
InternetAddress[] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Transport.send(msg); // ERROR IS IN THIS LINE...
out.println("INSIDE TRy");
out.println("
");
out.println("mail was sent to"+to);
out.println("from"+from);
out.println("using host" + host + ".");
out.println("
");
out.println("last");
}
catch(Exception e)
{
out.println("error");
}
finally
{
out.close();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
doGet(req,res);
}
}
can you tell where is the erroe in this we are using get method in HTM prog to call this JSP program
shruti
<<Less