javamail在连接问题....connection faild????救救我!!!

mfkfkpyu 2004-01-13 03:05:51


mail.jsp

<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
receive
</title>
</head>
<body>
<h1>
JBuilder Generated JSP
</h1>
<form method="post" action="loginmail">
<br>user : <input type="text" name="user"><br>
<br>password:</br><input type="text" name="password">
<input type="submit" name"B1" value="提交">
<input type="reset" value="全部重写" name="B2">
<br>

</form>
</body>
</html>



LoginMail.java:

package LoginMailServlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;
import java.text.*;
import java.util.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/

public class LoginMail extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String POP3Server="sohu.com";
String SMTPServer="smtp.sohu.com";
Session mailsession=null;
Store store;
Folder folder;
Message[] messages=null;
String user;
String password;

user=request.getParameter("user");
password=request.getParameter("password");
java.util.Properties properties=System.getProperties();
properties.put("mail.smtp.host",SMTPServer);

response.setContentType("text/html;charset=gb2312");
try{
DateFormat df=DateFormat.getDateTimeInstance( DateFormat.SHORT,DateFormat.SHORT,Locale.CHINESE);
mailsession=mailsession.getInstance(properties,null);
// 得到POP3 message store, 并连接
store = mailsession.getStore("pop3");
store.connect(POP3Server, user, password);

// 以只读的方式打开文件夹
folder=store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
messages=folder.getMessages();
HttpSession session=request.getSession(true);
session.putValue("MESSAGES",messages);
session.putValue("SESSION",mailsession);
session.putValue("USER",user);
session.putValue("PASSWORD",password);

out.print("<html>");
out.print("<head><title>收件箱内容</title></head>");
out.print("<body>");
out.print("<h1>收件箱内容</h1><hr>");
out.print("<table>");
out.print("<tr>"+
"<td>日期</td>"+
"<td>发件人</td>"+
"<td>主题</td>"+
"</tr>\n");

for(int i=0;i<folder.getMessages().length;i++){
out.print("<tr>"+
"<td>"+df.format(messages[i].getSentDate())+"</td>"+
"<td>"+getGBStr(messages[i].getFrom()[0].toString())+"</td>"+
"<td><a href='ReadMailServlet? index="+i+"'>"+getGBStr(messages[i].getSubject())+"</a></td>"+
"</tr>");
}
}catch(MessagingException e){
throw new ServletException("Exception:"+e);
}
out.println("</table>");
out.print("</body>");
out.print("</html>");
}

private String getGBStr(String s){
try{
String temp=s;
byte[] tempb=temp.getBytes("ISO8859-1");
String result=new String(tempb);
return result;
}
catch(Exception e){

}
return "null";
}

}



type Exception reportmessage Internal Server Errordescription The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.exception javax.servlet.ServletException: Exception:javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Operation timed out: connect
at LoginMailServlet.LoginMail.doPost(LoginMail.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
...
我输入已注册的sohu邮箱和密码,系统就报这个错.
帮忙看看!救救我吧.

...全文
39 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ddbean 2004-01-14
up
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-01-13 03:05
社区公告
暂无公告