java通过pop3协议如何获取信件内容!
v不吃v你 2001-02-07 04:16:00 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()));
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);
System.out.println("**********");
out.writeBytes("USER "+ "bootcool"+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("PASS "+ "bootcool"+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("STAT 1"+"\n");
out.writeBytes("LIST 1"+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("UIDL 1 "+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("RETR 1");
result = in.readLine();
System.out.println(result+"\n");
//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;
}
}