首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

帮一个忙好不?该如何处理

2012-02-05 
帮一个忙好不????这个是jsp页面%@pagecontentType text/htmlcharsetGB2312 %%request.setCharacte

帮一个忙好不????
这个是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 "> </td>
</tr>
<tr   bgcolor= "#FFFFFF ">  
<td> 主题: </td>
<td>  
<input   name= "title "   type= "text "   id= "title "> </td>


</tr>
<td   height= "107 "   colspan= "2 "   bgcolor= "#FFFFFF ">  
  <p> 正文: <br> <textarea   name= "message "   cols= "50 "   rows= "15 "   id= "content "> </textarea> </td>
</tr>
<tr   align= "center ">  
<td   colspan= "2 "   bgcolor= "#FFFFFF ">  
<input   type= "submit "   name= "Submit "   value= "发送 ">
<input   type= "reset "   name= "Submit2 "   value= "重置 ">
</td>
</tr>
</table>
</form>
</body>
</html>
我已经点击发送而且提示发送成功.但为什么我的邮箱里收不到我自已发的信息呢?还有每次要发送时我都要开启james服务器(双击run.bat文件和到cmd里输入telnet   localhost   4555),然后才发送.这个程序有错误吗?谁能帮帮我???在此谢了

[解决办法]
顶, 俺也找一到好方法,

推荐一下网站,找个组件:

jarakte.apach.com

热点排行