以下代码在window下登陆sina和139没有问题,但是在公司的linux服务器上就不行,求解决
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class test { public static void normalLogin(String popServer, String popUser,
String popPassword){

String POP3Server = popServer;
int POP3Port = 110;
Socket client = null;
try {
// 创建一个连接到POP3服务程序的套接字。
client = new Socket(POP3Server, POP3Port);
// 创建一个BufferedReader对象,以便从套接字读取输出。
InputStream is = client.getInputStream();
BufferedReader sockin;
sockin = new BufferedReader(new InputStreamReader(is));
// 创建一个PrintWriter对象,以便向套接字写入内容。
OutputStream os = client.getOutputStream();
PrintWriter sockout;
sockout = new PrintWriter(os, true); // true for auto-flush
// 显示POP3握手信息。
System.out.println("S:" + sockin.readLine()); /*--   与POP3服务器握手过程   --*/
System.out.print("C:");
String cmd = "user " + popUser;
// 将用户名发送到POP3服务程序。
System.out.println(cmd);
sockout.println(cmd);
// 读取POP3服务程序的回应消息。
String reply = sockin.readLine();
System.out.println("S:" + reply); System.out.print("C:");
cmd = "pass ";
// 将密码发送到POP3服务程序。
//System.out.println(cmd + "*********");
sockout.println(cmd + popPassword);
// 读取POP3服务程序的回应消息。
reply = sockin.readLine();
System.out.println("S:" + reply);

if(reply.contains("+OK")){
System.out.println("success");
}else
System.out.println("密码错误,或未开通POP服务。");
} catch (IOException e) {
System.out.println("连接超时");
} finally {
try {
if (client != null)
client.close();
} catch (IOException e) {
}
}

} /**
 * @param args
 */
public static void main(String[] args) {
normalLogin("pop.sina.com","[email protected]","password");
normalLogin("pop.sina.cn","[email protected]","password");
normalLogin("pop.139.com","[email protected]","password");
}}

解决方案 »

  1.   

    木有人啊。。难道javaee版块不行了?????????
      

  2.   

    请排除下面的情况,我以前遇见过
    linux服务器没有正常的访问外网,无法解析DNS ping pop.sina.com试试看
      

  3.   

    ping通了。。运行代码后连接超时。。等了半天木有反应。。
      

  4.   

    这段代码给修改下
    System.out.println("连接超时");
    别把异常给忽略吞食了,这样无法查错的System.out.println("连接超时");
             e.printStackTrace();
      

  5.   

    e.printStackTrace()出来也是连接超时,只是出来的是英文而已
      

  6.   

    算了,还是用javamail了。。麻烦就麻烦再要导入jar。。而且还有jar冲突的。。