How to use JSP to send messages

Source: Internet
Author: User

The

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= "></TEXTAREA"
</td>
</tr>
<tr>
<td width=80 height=30> How to address: <font color= #ff0000 >* </font></td>
<td><input class=input id=name name=name>
</td>
</TR>
<tr>
<td width=80 height=30> your message: <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: </td>
<td><input Name=phone Class=input id= "Phone"
</td>
</tr>
<tr>
<td width=80 height=45> Company Address:< Br>
(or Web site) </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=tt OnClick = "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" >
<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 This send </title>
<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 (A new internetaddress (from));
String To=email1;
Internetaddress[] Address=null;
Address = Internetaddress.parse (to,false);
//Newmessage.setrecipient (MeSsage. Recipienttype.to, New InternetAddress (Request.getparameter ("to"));
Msg.setrecipients (Message.RecipientType.TO, address);
//Set the recipient
Msg.setsubject ("online message:"); Set the purpose of the e-mail
msg.setsentdate (new Java.util.Date ());//Set the time for the Messenger
Msg.settext ("title: +topic+", Content "+body+", Contact Person e-mail: "+email+", Contact Tel: "+phone+", company website/address: "+http"; Custom Messenger MIME Type
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 (' successful message!! '); window.location.href= ' message.jsp ';</script> ");

}catch (Exception e) {
Out.println (e.tostring ());
}

%>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.