help me IN JAVA MAIL

HI TO ALL......

I AM NEW TO THIS FIELD....I AM TRYING TO SEND EMAIL THROUGH JAVA MAIL FUNCTION......,FIRST I AM FETCHING THE MAIL ADDRESS FROM DATA BASE.....I WANT TO SEND MAIL TO THOSE ADDRESS......HERE I M LITTLE BIT CONFUSED....PLZ HELP ME....BELOW IS THE CODE.........

THIS FOR SEARCHING THE MAIL IDS......(SearchEmail .java)

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.sql.*;

public class SearchEmail extends HttpServlet {

public String s1;

public String username="root";

public String passWord="";

public String url="jdbc:mysql://192.168.0.7:3306/ias";

private String SUB_NO="";

private String ST_DT="";

private String EMAIL="";

public void init() {

try {

Class.forName("sun.mysql.Jdbc.Driver");

System.out.println("JDBC driver loaded");

}

catch (ClassNotFoundException e) {

System.out.println(e.toString());

}

}

/**Process the HTTP Get request*/

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

sendPageHeader(response);

sendSearchForm(response);

sendPageFooter(response);

}

/**Process the HTTP Post request*/

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

ST_DT = request.getParameter("ST_DT");

sendPageHeader(response);

sendSearchForm(response);

sendSearchResult(response);

sendPageFooter(response);

}

public void sendSearchResult(HttpServletResponse response)

throws IOException {

PrintWriter out = response.getWriter();

try {

Connection con = DriverManager.getConnection(url,username,passWord);

System.out.println("got connection");

Statement s = con.createStatement();

String sql= "SELECT EMAIL " + "FROM temp "+

"WHERE ST_DT='" + ST_DT + "' AND EMAIL!='" + null + "'";

ResultSet rs = s.executeQuery(sql);

StringBuffer sb = new StringBuffer(100);

while (rs.next()) {

String SUB_NO = rs.getString(1);

s1 =sb.append( rs.getString(1)).append(",").toString();

}

out.println("<TABLE border='1'>");

out.println("<TR>");

out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' ></TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE=veda@ias.ernet.in ></TD>");

out.println("</TR>");

out.println("</TR>");

out.println("<TD>SUBJECT</TD><TD><INPUT TYPE=TEXT SIZE='50' NAME=SUBJECT></TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>MESSAGE </TD><td><textarea cols='70' rows='20' name='MESSAGE'>");

out.println("C.Vedamurthy senior");

out.println("Administrative Assistant");

out.println("Indian Academy of Sciences");

out.println("C.V.Raman Avenue,Near Mekhri Circle");

out.println("Post Box No 8005,sadashivanagar'");

out.println("bangalore 560080");

out.println("office no 23612546,23611034,23612943 extn 207 ");

out.println("res 23431357;Fax 23616094;");

out.println("</textarea></td>");

out.println("</TR>");

out.println("<table align='center'>");

out.println("<TR>");

out.println("<form action='mailservlet' method='post' name='myform'>");

out.println("<CENTER> <TD><INPUT TYPE='SUBMIT' VALUE='send'></INPUT></TD></CENTER>");

out.println("</form>");

out.println("</TR>");

out.println("</TABLE>");

rs.close();

s.close();

con.close();

}

catch (SQLException e) {

}

catch (Exception e) {

out.println("</TABLE>");

}

}

/**

* Send the HTML page header, including the title

* and the <BODY> tag

*/

private void sendPageHeader(HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<HTML>");

out.println("<HEAD>");

out.println("<TITLE>Displaying Selected Record(s)</TITLE>");

out.println("</HEAD>");

out.println("<BODY BGCOLOR=#FFE4C4>");

out.println("<CENTER>");

}

/**

* Send the HTML page footer, i.e. the </BODY>

* and the </HTML>

*/

private void sendPageFooter(HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

out.println("</CENTER>");

out.println("</BODY>");

out.println("</HTML>");

}

/**Send the form where the user can type in

* the details for a new user

*/

private void sendSearchForm(HttpServletResponse response)

throws IOException {

PrintWriter out = response.getWriter();

out.println("
<H2>Search</H2>");

out.println("
");

out.println("
<FORM METHOD=POST>");

out.print("START DATE: <INPUT TYPE=TEXT Name=ST_DT");

out.print(" VALUE=\"" + ST_DT + "\"");

out.println(">");

out.println("<BOTTOM>");

out.println("<TABLE ALIGN='CENTER'>");

out.println("<INPUT TYPE=SUBMIT VALUE=submit>");

out.println("</TABLE>");

out.println("</FORM>");

}

}

THIS IS JAVA MAIL FUNCTION.........(mailservlet .java)

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import javax.mail.*;

import javax.mail.internet.*;// important

import javax.mail.event.*;// important

import java.net.*;

import java.util.*;

import javax.mail.MessagingException;

public class mailservlet extends HttpServlet

{

public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException, IOException

{

PrintWriter out=response.getWriter();

response.setContentType("text/html");

try

{

Properties props=new Properties();

props.put("mail.smtp.host","localhost");// 'localhost' for testing

Sessionsession1 = Session.getDefaultInstance(props,null);

String s1 = request.getParameter("FROM"); //sender (from)

String s2 = request.getParameter("EMAIL");

String s3 = request.getParameter("SUBJECT");

String s4 = request.getParameter("MESSAGE");

Message message =new MimeMessage(session1);

message.setFrom(new InternetAddress(s1));

message.setRecipients

(Message.RecipientType.TO,InternetAddress.parse(s2,false));

message.setSubject(s3);

message.setText(s4);

Transport.send(message);

out.println("mail has been sent");

}

catch(Exception ex)

{

out.println("COULD NOT SEND EMAIL.....");

}

}

}

plz help me its very urgent ........

[7436 byte] By [god_bless1_you1a] at [2007-11-27 3:47:08]
# 1

>out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' ></TD>");

>out.println("</TR>");

>out.println("<TR>");

>out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE=veda@ias.ernet.in ></TD>");

You didn't put names to those fields above:

out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' name ='EMAIL'></TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='veda@ias.ernet.in' name='FROM'></TD>");

also try:

catch(Exception ex)

{

out.println("COULD NOT SEND EMAIL.....");

ex.printStackTrace();

}

to know what is exactly the error.

danilexa at 2007-7-12 8:50:52 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' name ='EMAIL'></TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='veda@ias.ernet.in' name='FROM'></TD>");

also try:

catch(Exception ex)

{

out.println("COULD NOT SEND EMAIL.....");

ex.printStackTrace();

}

i tried this but when i run the program ...

mail ids coming in text box when i click the send button "could not send mail" message coming like this......

whatever i wrote the program is right or wrong.....

plz help me........

god_bless1_you1a at 2007-7-12 8:50:52 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

You need to learn about his new concept we call "debugging".

You need to collect more information about what your program is doing

and compare that with what you think it should be doing. If they don't

match, and you can't figure out why, post both pieces of information

here.

In particular, if you're getting an exception, post the details of the exception!

Also, please read the JavaMail FAQ for more debugging tips.

bshannona at 2007-7-12 8:50:52 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...