| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 948 人关注过本帖
标题:JSP 发邮件出问题!
取消只看楼主 加入收藏
HB515560244
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-10-9
收藏
 问题点数:0 回复次数:2 
JSP 发邮件出问题!

代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'Login.jsp' starting page</title>
</head>

<body>
<form action="sendmail.jsp" method=post>
<table>
<tr><td>收件人:<input type=text name=to></td></tr>
<tr><td>发件人:<input type=text name=from></td></tr>
<tr><td>主题:<input type=text name=subject></td></tr>
<tr><td>内容;<textarea name=content></textarea>
<tr><td><input type=submit value=send ><input type=reset value=aaa></td></tr>
</table>
</form>
</body>
</html>

处理页面:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="javax.mail.*, javax.mail.internet.*, javax.activation.*, java.util.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'sendmail.jsp' starting page</title>
</head>
<% request.setCharacterEncoding("gb2312"); %>
<body>
<%
try{
Properties props=System.getProperties();
Session sendmailSession;
Transport transport;

sendmailSession=Session.getDefaultInstance(props,null);
props.put("mail.smtp.host","smtp.sina.com.cn");
//props.put("mail.smtp.prot","25");
Message newMessage=new MimeMessage(sendmailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.addRecipient(Message.RecipientType.TO,new InternetAddress(request.getParameter("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("content"));
transport =sendmailSession.getTransport("smtp");
transport.send(newMessage);

%>
<p>你的邮件已发送,请返回。</p>

<%
}
catch(MessagingException e){
out.print("错误原因是:"+e);
}
%>
</body>
</html>

错误原因是:javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.SendFailedException: Invalid Addresses; nested exception is: class javax.mail.SendFailedException: 554 : Client host rejected: Access denied

是不是我没装SMTP服务器的问题啊?要装这个服务器吗?哪位能帮我改改吗?


搜索更多相关主题的帖子: JSP 邮件 
2007-11-16 16:57
HB515560244
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-10-9
收藏
得分:0 
收件人我写的是:xing@sina.com
2007-11-16 16:58
HB515560244
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-10-9
收藏
得分:0 

那 user和pwd怎么得到啊,

props.put("mail.smtp.host", "smtp.163.com");//这个有什么用啊?应该怎么设置啊,如果我是发给新浪的,或其他的呢???

谢谢啊,在线..

2007-11-16 22:16
快速回复:JSP 发邮件出问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029492 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved