程序实现发送邮件
需要提前注册两个邮箱才能实验,代码是参考方立勋javaweb教程写的
//发邮件首先连上服务器 Socket socket = new Socket("smtp.sohu.com",25); OutputStream out = socket.getOutputStream();//向服务器写数据 BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); System.out.println(in.readLine()); out.write("ehlo flx\r\n".getBytes()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); out.write("auto login\r\n".getBytes()); System.out.println(in.readLine()); out.write("axxxx".getBytes()); System.out.println(in.readLine()); out.write("afewaxxx".getBytes()); System.out.println(in.readLine()); out.write("mail from:<itcast1111@sohu.com>\r\n".getBytes()); System.out.println(in.readLine()); out.write("mail to:<itcast1111@sina.com>\r\n".getBytes()); System.out.println(in.readLine()); out.write("data\r\n".getBytes()); out.write("fawefawefawefawefawef\r\n".getBytes()); out.write(".\r\n".getBytes()); System.out.println(in.readLine()); out.write("quit".getBytes());