以下程序在往163.com的邮箱发邮件时,报 Exception in thread "main" java.net.UnknownHostException: mailhost。
请大侠看看问题
public class SendMail { public static void main(String[] args) throws IOException { // if (args.length == 1) // System.getProperties().put("mail.host", args[0]); Properties props = System.getProperties(); props.put("mail.smtp.host", "smtp.163.com"); props.put("mail.smtp.port", "110"); props.put("mail.smtp.auth", "true"); 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 url = new URL("mailto:" + to); URLConnection c = url.openConnection(); c.setDoInput(false); c.setDoOutput(true); c.connect(); System.out.println("Connecting......"); PrintWriter out = new PrintWriter(c.getOutputStream()); out.print("From: \"" + from + "\" <" + System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getHostName() + ">\r\n"); out.print("To: " + to + "\r\n"); out.print("Subject: " + subject + "\r\n"); out.print("\r\n"); System.out.println("Enter the mail message. End with a '.' on a line by itself."); String line; for(;;) { line = in.readLine(); if (line == null || line.equals(".")) break; out.print(line); } out.close(); in.close(); } }