Write a mail sender with Java

zhaozj2021-02-08  371

Import java.net. *; import java.io. *; import java.net. *; public class sendelvismail {public static void main (string s []) {/// send fake mail from elvis presley ///// sendElvisMail [mail server] [recipient address] // mail server can be hostname or IP address // // ex sendElvisMail mail.company.com myFriend@somewhere.qc.ca // sendElvisMail t = new sendElvisMail ();. t. sendMail (s [0], s [1]);} public void sendMail (String mailServer, String recipient) {try {Socket s = new Socket (mailServer, 25); BufferedReader in = new BufferedReader (new InputStreamReader (s.getInputStream (), "8859_1"); bufferedwriter out = new bufferedwriter (S. GetputStream (), "8859_1")); Send (In, Out, "Helo the the TheWorld); // Warning: Some Mail Server Validate The sender address // in the mail from command, put your real address here send (i N, OUT, "Mail from: "); Send (in, out, "rcpt to:" Recipient); Send (in, out, "data"); send (out, "Subject: in the ghetto"; send (out, "from: elvis presley "); send (out, "/ n"); // Message Body Send (OUT, "i 'm alive. Help Me! "); Send (OUT," /N./N "); Send (in, out," quit "); s.close ();} catch (exception e) {E.PrintStackTrace ();}} Public void send (bufferedreader in, bufferedwriter out, string s) {try {out.write (s

"/ n"); out.flush (); system.out.println (s); s = in.printLine (); system.out.println (s);} catch (Exception E) {E.PrintStackTrace () }}} Public void send (bufferedwriter out, string s) {Try {Out.write (S "/ N"); out.flush (); system.out.println (s);} catch (exception e) { E.PrintStackTrace ();}}}

转载请注明原文地址:https://www.9cbs.com/read-852.html

New Post(0)