遇到了java smtp 郵件問題,哪位高手能夠相助啊?

hgwnet發表於2004-05-05
為什麼smtp的DATA指令與其結束標誌.之間無法執行任何動作呢,哪怕是設定郵件標題???具體錯誤顯示如下相關中文註釋。

完整程式碼如下:
so = new Socket("218.79.108.205", 25);
send = new PrintWriter(so.getOutputStream(), true);
recv = new BufferedReader(new InputStreamReader(so.getInputStream()));
String s1 = recv.readLine();
char c = s1.charAt(0);
if ((c == '4') | (c == '5'))
System.out.println("error");

System.out.println("Socket send cmd:" + "HELO " + "gb.com");
send.println("HELO " + "gb.com");
System.out.println("Socket received msg:" + recv.readLine());

System.out.println("Socket send cmd:" + "MAIL FROM:" + "test@localhost");
send.println("MAIL FROM:" + "test@localhost");
System.out.println("Socket received msg:" + recv.readLine());

System.out.println("Socket send cmd:" + "RCPT TO:" + "hgwstart@hotmail.com");
send.println("RCPT TO:" + "hgwstart@hotmail.com");
System.out.println("Socket received msg:" + recv.readLine());

System.out.println("Socket send cmd:" + "DATA");
send.print("DATA");
// System.out.println("Socket received msg:" + recv.readLine());這條測試語句加入後執行變成無限等待相應。


// send.print("Subject: " + "test subject" + "\r");這條語句加入後系統提示:502 Unknown command,然後執行中斷。


send.print("\n.\n");

send.println("QUIT");
System.out.println("Socket received msg:" + recv.readLine());

System.out.println("End...");

//上述程式可以直接複製到編譯執行,但前提是要本機執行一個smtp server,例如ArGoSoft mail server

相關文章