日期:2014-05-18  浏览次数:20767 次

帮一个忙好不????
这个是jsp页面
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<%request.setCharacterEncoding( "gb2312 ");%>
<%@   page   import= "java.util.*,javax.mail.* "%>
<%@   page   import= "javax.mail.internet.* "%>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 发送成功 </title>
</head>

<body>
<%
try{
String   tto=request.getParameter( "to ");
String   ttitle=request.getParameter( "title ");
String   tcontent=request.getParameter( "message ");
Properties   props=new   Properties();
props.put( "mail.smtp.host ", "localhost ");
props.put( "mail.smtp.auth ", "true ");
Session   s=Session.getInstance(props);
s.setDebug(true);

MimeMessage   message=new   MimeMessage(s);


InternetAddress   from=new   InternetAddress( "jspmail123@126.com ");//设置收信人
message.setFrom(from);
InternetAddress   to=new   InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject(ttitle);//设置主题
message.setSentDate(new   Date());


//给消息对象设置内容
BodyPart   mdp=new   MimeBodyPart();//新建一个存放信件内容的BodyPart对象
mdp.setContent(tcontent, "text/html;charset=gb2312 ");   //给BodyPart对象设置内容和格式/编码方式
Multipart   test=new   MimeMultipart();//新建一个MimeMultipart对象用来存放对象

test.addBodyPart(mdp);//将BodyPart加入到MimeMultipart对象中
message.setContent(test);//把mm作为消息对象的内容

message.saveChanges();
Transport   transport=s.getTransport( "smtp ");
transport.connect( "localhost ", "jspmail123 ", "123456 ");
transport.sendMessage(message,message.getAllRecipients());
transport.close();
%>
<div   align= "center ">
<p> <font   color= "#FF6600 "> 发送成功! </font> </p>
<br>

</div>
<%
}catch(MessagingException   e){
out.println(e.toString());
}
%>
</body>
</html>
以下是html页面
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 写邮件 </title>
</head>

<body>
<form   name= "form1 "   method= "post "   action= "Testmail02.jsp ">
<table   width= "75 "   border= "0 "   align= "center "   cellspacing= "1 "   bgcolor= "#006666 "   >
<tr   bgcolor= "#FFFFFF ">  
<td   width= "40% "> 收信人地址: </td>
<td   width= "80% ">  
<input   name= "to "   type= "text "   id= "to "> </td>
</tr>
<tr   bgcolor= "#FFFFFF ">  
<td   width= "40% "> 发信人地址: </td>
<td   width= "80% ">  
<input   name= "to "   type= "text "   id= "from &qu