?? smtpclient.java
字號:
import java.io.*;import java.net.*;//本程序實現郵件傳輸功能public class SMTPClient { public static void main(String[] args) { try { if (args.length >= 1) System.getProperties().put("mail.host", args[0]); BufferedReader in =new BufferedReader(new InputStreamReader(System.in)); System.out.print("From: "); String from = in.readLine(); System.out.print("To: "); String to = in.readLine(); System.out.print("Subject: "); String subject = in.readLine(); URL u = new URL("mailto:" + to); URLConnection c = u.openConnection(); c.setDoInput(false); c.setDoOutput(true); System.out.println("Connecting..."); System.out.flush(); c.connect(); PrintWriter out = new PrintWriter(new OutputStreamWriter(c.getOutputStream())); out.print("From: \"" + from + "\" <" + System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getHostName() + ">\n"); out.print("To: " + to + "\n"); out.print("Subject: " + subject + "\n"); out.print("\n"); System.out.println("Enter the message. " + "End with a '.' on a line by itself."); String line; for(;;) { line = in.readLine(); if ((line == null) || line.equals(".")) break; out.print(line + "\n"); } out.close(); System.out.println("Message sent."); } catch (Exception e) { System.err.println(e); System.err.println("Usage: java SMTPClient [<mailhost>]"); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -