⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtpclient.java

📁 《JAVA分布式程序设计》一书的源代码。
💻 JAVA
字号:
import java.io.*;import java.net.*;/** * @(#)smtpClient.java * @author Qusay H. Mahmoud */public class smtpClient {   public static void main(String[] args) {      Socket smtpSocket = null;      DataOutputStream os = null;      BufferedReader is = null;      try {        smtpSocket = new Socket("MailMachine.com", 25);        os = new DataOutputStream(smtpSocket.getOutputStream());        is = new BufferedReader(new InputStreamReader (smtpSocket.getInputStream()));      } catch (UnknownHostException e) {        System.err.println("Don't know host: hostname");      } catch (IOException e) {         System.err.println("Couldn't get I/O to");      }      // If everything has been initialized then we want to write some data to      // the socket we have opened a connection to on port 25      if (smtpSocket != null && os != null &&is != null) {         try {           // The capital string before each colon has a              // special meaning to SMTP you may want to read            // the SMTP specification, RFC1822/1823           os.writeBytes("HELO\n");           os.writeBytes("MAIL From: dejavu@acm.org");           os.writeBytes("RCPT To:dejavu@acm.org\n");           os.writeBytes("DATA\n");      	   os.writeBytes("From: dejavu@acm.org\n");      	   os.writeBytes("Subject: testing\n");      	   os.writeBytes("Hi there\n"); // message body      	   os.writeBytes("\n.\n");      	   os.writeBytes("QUIT");           // keep on reading from/to the socket till we receive the "Ok" from            // SMTP, once we received that then we want to break.      	   String responseLine;      	   while ((responseLine = is.readLine()) != null) {             System.out.println("Server: " +responseLine);             if (responseLine.indexOf("Ok") != -1) {               break;             }      	   }           // clean up:           os.close();           is.close();           smtpSocket.close();    	 } catch (UnknownHostException e) {            System.err.println("Trying to connect to unknown host: " +e);         } catch (IOException e) {  	    System.err.println("IOException:  " + e);         }      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -