Re: who can give a simple example? Urgently need!!
"Flamingo" <gsuxin@gmail.com> wrote in message
news:1161268631.340033.304280@i3g2000cwc.googlegroups.com...
Hi folks,
I want a webpage, there would be a input textfield, and a "sumbit"
there, if you press the submit button, the contents you input to the
textfield would be send to your email. who can give me a simple sample
about that. thanks a lot. I really need i t urgently.
Here is an example from Peter van der Linden's Just Java 6th edition page
659. I hope it will get you started and you can figure out the rest.
import java.io.*;
import java.net.*;
public class email {
public static void main(String args[]) throws IOException {
Socket sock = null;
BufferedReader bis = null;
PrintStream ps = null;
try {
sock = new Socket("localhost", 25);
bis = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
ps = new PrintStream(sock.getOutputStream());
ps.println("mail from: trelford");
//System.out.println( dis.readLine() );
// Exercise for student:
// check all responses from the SMTP server
// They should all start with "2nn" or "3nn"
// Any different reply code means a failure to send mail.
System.out.println(bis.readLine());
} catch (IOException ioe) {
System.out.println("Sorry, your system is not running a
mailserver on port 25");
System.exit(0);
}
String Addressee= "linden";
ps.println("rcpt to: " + Addressee);
//System.out.println( dis.readLine() );
System.out.println(bis.readLine());
ps.println("data");
//System.out.println( dis.readLine() );
System.out.println(bis.readLine());
ps.println("This is the message\n that Java sent");
ps.println(".");
System.out.println(bis.readLine());
ps.flush();
sock.close();
}
}