?? accesspop3.java
字號:
import java.io.*;
import java.net.*;
import java.util.*;
public class AccessPOP3
{
private static final int POP3_PORT = 110;
public static void main(String[] args)
{
Socket mailSocket;
BufferedReader socketInput;
DataOutputStream socketOutput;
//檢查命令行參數
if (args.length < 4)
{
System.out.println(
"\nUsage: AccessPOP3 <host> <username> <password> <command>");
System.out.println("Parameters:");
System.out.println(
"\thost = Name or IP address of POP3 mail Server.");
System.out.println("\tusername = Account on POP3 mail Server.");
System.out.println("\tpassword = Password on POP3 mail Server.");
System.out.println("\tcommand = POP3 Command.");
System.out.println("Example:");
System.out.println(
"\tjava AccessPOP3 hotmail.yn.cninfo.net yshf 111111 STAT");
System.out.println(
"\tjava AccessPOP3 hotmail.yn.cninfo.net yshf 111111 LIST 2");
System.exit(1); //退出
}
try {
//連接POP3郵件服務器
System.out.println("Connecting ...");
mailSocket = new Socket(args[0], POP3_PORT);
//創建socket的輸入/輸出流,用于網絡通信
socketInput = new BufferedReader(
new InputStreamReader(mailSocket.getInputStream()));
socketOutput = new DataOutputStream(mailSocket.getOutputStream());
// 獲得POP3郵件服務器的初始信息
DisplayReply(socketInput);
//登錄POP3郵件服務器
System.out.println("USER " + args[1]);
socketOutput.writeBytes("USER " + args[1] + "\r\n");
DisplayReply(socketInput);
System.out.println("PASS " + args[2]);
socketOutput.writeBytes("PASS " + args[2] + "\r\n");
DisplayReply(socketInput);
//發送請求,以回車和換行(<CRLF>)結尾
for (int i = 3; i < args.length; i++)
socketOutput.writeBytes(args[i] + " ");
socketOutput.writeBytes("\r\n");
DisplayReply(socketInput);
//退出POP3郵件服務器
System.out.println("QUIT " + "\r\n");
//關閉BufferedReader和DataOutputStream對象
socketInput.close();
socketOutput.close();
//關閉socket連接
mailSocket.close();
}catch(Exception theException) {
System.out.println(theException);
}
System.exit(0); //退出
}
//接收并顯示POP3郵件服務器的響應信息
private static void DisplayReply(BufferedReader reader)
throws IOException, Exception
{
String s;
s = reader.readLine();
System.out.println(s);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -