我想跟其他语言没有什么两样,创建socket 通过110 port取信.
用telnet就是:
              telnet pop3.sina.com 110
              USER   XXX
              PASS   XXXXXX
              LIST   
用socket发送每一次上面的指令,然后看接受mail server的返回信息返回信息一般有'OK'就代表成功了.
LIST能列出有多少信.具体pop3协议请参照(RFC1939)
但你接了信,附件你只能得到是编过码(base64,printable...)的正文,你要根据头来采取一种解码.具体编码方式每种都不一样,看了邮件你就知道了.            

解决方案 »

  1.   

    能否自己用socket编程实现呢?
    in = new BufferedReader(new InputStreamReader (sock.getInputStream(),"8859_1")); 
    out = new DataOutputStream(sock.getOutputStream()); result = in.readLine(); 
    System.out.println(result); out.writeBytes("HELO "+ "bootcool"+"\n"); 
    System.out.println("HELO "+ InetAddress.getLocalHost ().getHostAddress()+"\n"); result = in.readLine(); 
    System.out.println(result); 
    System.out.println("**********");out.writeBytes("USER "+ "********"+"\n"); 
    result = in.readLine(); 
    System.out.println(result); out.writeBytes("PASS "+ "*********"+"\n"); 
    result = in.readLine(); 
    System.out.println(result); out.writeBytes("STAT "+"\n"); out.writeBytes("UIDL "+"\n");
    result = in.readLine();
    System.out.println(result);out.writeBytes("LIST "+"\n"); 
    result = in.readLine();
    System.out.println(result); 
    out.writeBytes("RETR 1");
    result = in.readLine();
    System.out.println(result);可是这里的输出却是null不知如何才能得到正文的内容呢?
      

  2.   

    你用的方法没错!
    你发出的USER ,PASS 指令确定成功了吗?
    如果成功pop3 server返回的信息如pop3.sina.com.cn 是+OK,你就可以判断有没有这个字串,有就是成功了.
    再试一试.
      

  3.   

    +OK incore system mail POP3 Server ready
    HELO 202.96.44.43+OK POP3 Example Server Ready
    **********
    +OK core mail
    +OK 5 message(s) [2543 byte(s)]
    +OK 5 2543
    +OK 5 2543
    QUIT但是如何才能在客户端得到邮件的正文内容呢?
    就像foxmail那样.
      

  4.   

    //20分太少了点吧用RETR 指令取得邮件的正文!
    你应该能取得类似以下内容
    这是一封csdn发给我的信.Return-Path: <[email protected]>
    Delivered-To: [email protected]
    Received: (qmail 82745 invoked from network); 7 Feb 2001 02:50:05
    Received: from unknown (HELO midatech.com) (211.100.8.152)
      by 202.106.187.186 with SMTP; 7 Feb 2001 02:50:05 -0000
    Received: from csdnmail [211.101.228.181] by midatech.com
      (SMTPD32-5.01 EVAL) id A61F7630260; Wed, 07 Feb 2001 10:38:23 PS
    From: CSDN专家门诊<[email protected]>
    To: [email protected]
    Subject: 关于:跟ejb有关的问题
    Reply-To: 此信不能回,请到论坛发言
    Mime-Version: 1.0
    Content-Type: text/plain; charset=gb2312
    Message-Id: <200102071038.SM00158@csdnmail>
    Date: Wed,  7 Feb 2001 10:38:24 PST
    cming,您好:
    关于:跟ejb有关的问题
    robber提供了如下回答, 请您查阅和评估:
    ----------------------------------------------------由container来完成可能更易于控制吧!----------------------------------------------------
    如果这个回复已经解决了您的问题,请到论坛给分给回答您问题的用户。
    问题:http://www.csdn.net/expert/TopicView.asp?id=65774
    中国软件开发网络: http://www.csdn.net/
    中国软件开发网络专家门诊: http://expert.csdn.net/
    .看到最后的.没有?这就是正文结束的标志.这是没有附件的,有附件的就麻烦了,得自己解码了,最常见的是base64,你自己写段base64解码的java代码.
    取附件与内容,有分割标志如新浪的是:
       boundary="----------97401812817428SINAEMAIL---"
    你的pop3 server也有,自己好好看看.
      

  5.   

    可是我的RETR 1 却什么都没有.
    这是我的原码.
    import java.io.*; 
    import java.net.*; 
    import java.util.*;public class mypop3 { public static void main(String[] args) throws IOException, UnknownHostException 
    { String mailHost; 
    mailHost = "263.net"; 
    POP3Connection mail = new POP3Connection(mailHost); 
    mail.Receive();

    } class POP3Connection 

     final static int PORT = 110; 
     static InetAddress r_ip; public POP3Connection(String host) throws UnknownHostException 

     r_ip = InetAddress.getByName(host); 
    } public boolean Receive() throws IOException 

    // Create Socket 
     BufferedReader in, msg; 
     DataOutputStream out; 
     Socket sock; 
     String result, line,pass,name;  if ((sock = new Socket(r_ip, PORT)) == null) 
      return false;  in = new BufferedReader(new InputStreamReader (sock.getInputStream(),"8859_1")); 
     out = new DataOutputStream(sock.getOutputStream()); 
     
     result = in.readLine(); 
     System.out.println(result); 
     
     out.writeBytes("HELO "+ "bootcool"+"\n");
     System.out.println("HELO "+ r_ip.getHostAddress()+"\n"); 
     
     result = in.readLine(); 
     System.out.println(result); 
     
     out.writeBytes("USER "+ "bootcool"+"\n"); 
     result = in.readLine(); 
     System.out.println(result); 
     
     out.writeBytes("PASS "+ "********"+"\n"); 
     result = in.readLine(); 
     System.out.println(result);  
     out.writeBytes("STAT "+"\n"); 
     
     out.writeBytes("LIST "+"\n"); 
     result = in.readLine();
     System.out.println(result);  out.writeBytes("RETR 1");
    result = in.readLine();
    System.out.println(result); 
     out.writeBytes("UIDL 1 "+"\n");
     result = in.readLine();
     System.out.println(result);
     
     //out.writeBytes("TOP 1"+"\n");
     //result = in.readLine();
     //System.out.println(result);
    //out.writeBytes("DELE 1"+"\n"); 
     //result = in.readLine(); 
    //System.out.println(result); 
     
     out.writeBytes("QUIT"+"\n"); 
     System.out.println("QUIT"); 
     result = in.readLine(); 
     System.out.println(result); 
      
     sock.close();  return true; 
     } 

    不知错在哪了?
    请指教.
    求求了
    我会加分的.
      

  6.   

    问题应该在你用readline来取数据,信的头,内容,附件加起来怎么可能只有一行,得用循环
       循环条件是
               判断 "/n" + "." + "/n" 这个字串出现了没有,
     
          if 有
                 收完 
                 退出
           else
                 继续收
      

  7.   

    修改如下;out.writeBytes("STAT 1"+"\n"); 
     
     out.writeBytes("LIST 1"+"\n"); 
     result = in.readLine();
     System.out.println(result);  out.writeBytes("RETR 1");
     
     
     for( result = in.readLine(); result!= "/n" + "." + "/n"  ; result = in.readLine())
     { System.out.println(result);
     }
     out.writeBytes("UIDL 1 "+"\n");
     result = in.readLine();
     System.out.println(result);
    可是好像还是不行.
    你说得很对.
    可是可是System.out.println(result);
    却看不到内容.
      

  8.   

    还是不行.
    我想就是
    for( result = in.readLine(); result!= "\n" + "." + "\n"  ; result = in.readLine())
    { System.out.println(result);
    }
    这有不对的地方.
    结果总是
    null
    null
    null
    null
    ......
    不能用=;但是我看了一下java函数
    好像没有包含
    不过我想是不是能用indexOf(),HE和subString()两个结合着用呢?
    请指教呀.
    太谢谢了.
      

  9.   

    对,就是用String的indexOf(),方法肯定没有错,有空再看看RFC1939中关于邮件正文结束的那一段.试试这个:
    endString = "\n" + "." + "\n";
    while(result.indexOf(endString) == -1)

        result + =  in.readLine();
        //System.out.println(result);
     }
    System.out.println(result);
      

  10.   

    改为:
    out.writeBytes("RETR 1"+"\n");
     String endString = "\n" + "." + "\n";
     while(result.indexOf(endString) == -1)
     { 
        result = in.readLine();
        System.out.println(result);
     }
    不用result + = in.readLine();
    谢谢.还请今后多多指教呀!