MESSAGE. JSP
<TABLE width = 555 border = 0 align = "center" cellPadding = 0 cellSpacing = 0>
<FORM action = message_do.jsp method = post>
<TBODY>
<TR>
<TD width = 80 height = 30> letter title: <FONT color = # ff0000> * </FONT> </TD>
<TD> <INPUT class = input id = topic name = topic>
</TD>
</TR>
<TR>
<TD width = 80 height = 23 valign = "top"> feedback: <FONT color = # ff0000> * </FONT> </TD>
<TD> <TEXTAREA class = input id = body name = body rows = 5 cols = "50"> </TEXTAREA>
</TD>
</TR>
<TR>
<TD width = 80 height = 30> title: <FONT color = # ff0000> * </FONT> </TD>
<TD> <INPUT class = input id = name>
</TD>
</TR>
<TR>
<TD width = 80 height = 30> your email: <FONT color = # ff0000> * </FONT> </TD>
<TD height = 23> <INPUT class = input id = email name = email>
</TD>
</TR>
<TR>
<TD width = 80 height = 30> your phone number: </TD>
<TD> <INPUT name = phone class = input id = "phone">
</TD>
</TR>
<TR>
<TD width = 80 height = 45> company address: <BR>
(Or URL) </TD>
<TD> <INPUT class = input id = http size = 40 name = http>
</TD>
</TR>
<TR>
<TD align = right width = 80> & nbsp; </TD>
<TD height = 35> <INPUT class = bt type = submit value = submit name = ttOnclick= "Return check ()">
</TD>
</TR>
</FORM>
</TABLE>
Processing page:
<% @ Page contentType = "text/html; charset = gb2312" language = "java" import = "java. SQL. *, java. util. *, javax. mail. *, cn. cmpy. company. *, javax. mail. internet. *, javax. activation. * "errorPage =" "%>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Jsp: useBean id = "company" scope = "page" class = "cn. cmpy. company. company"> </jsp: useBean>
<Jsp: useBean id = "comCtl" scope = "page" class = "cn. cmpy. company. comCtl"> </jsp: useBean>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> message book sending </title>
</Head>
<Body>
<%
// Int id = 1;
Company = comCtl. selectCompany (1 );
String email1 = "";
Email1 = company. getEmail ();
If (email1 = null) email1 = "nbybc@sina.com ";
String username = request. getParameter ("name ");
String topic = request. getParameter ("topic ");
String body = request. getParameter ("body ");
String email = request. getParameter ("email ");
String phone = request. getParameter ("phone ");
String http = request. getParameter ("http ");
// String email = new String (request. getParameter ("email"). getBytes ("ISO8859_1 "));
// Out. print (username + "<br> ");
// Out. print (email + "<br> ");
Try {
Properties props = new Properties ();
Props. put ("mail. smtp. host", "smtp.sohu.com ");
Props. put ("mail. transport. protocol", "smtp ");
Props. put ("mail. smtp. auth", "true ");
Javax. mail. Session sessmail = javax. mail. Session. getInstance (props );
Message msg = new MimeMessage (sessmail );
String From = "sonic260@sohu.com ";
Msg. setFrom (new InternetAddress (From ));
String To = email1;
InternetAddress [] address = null;
Address = InternetAddress. parse (To, false );
// NewMessage. setRecipient (Message. RecipientType. TO, new InternetAddress (request. getParameter ("")));
Msg. setRecipients (Message. RecipientType. TO, address );
// Set the recipient
Msg. setSubject ("online message:"); // set the subject of email
Msg. setSentDate (new java. util. Date (); // set the sending time
Msg. setText ("title:" + topic + ", content" + body + ", contact email:" + email + ", contact number:" + phone + ", company website/address: "+ http); // set the MIME Type of the sender message
Transport transport = sessmail. getTransport ("smtp ");
Transport. connect ("smtp.sohu.com", "sonic260", "123456789 ");
Transport. sendMessage (msg, msg. getAllRecipients ());
Transport. close ();
Out. print ("<script language = 'javascript '> alert (' message has been sent successfully !! '); Window. location. href = 'message. jsp'; </script> ");
} Catch (Exception e ){
Out. println (e. toString ());
}
%>
</Body>
</Html>