我给你一段源程序:
/*
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class Email extends Applet
{
public void init()
{
// Take out this line if youdo
n't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(560,477);
label1 = new java.awt.Label("MailTo:");
label1.setBounds(60,48,48,24);
add(label1);
txtMailTo = new java.awt.TextField();
txtMailTo.setBounds(108,48,300,24);
add(txtMailTo);
label2 = new java.awt.Label("RcvFrom");
label2.setBounds(48,72,48,24);
add(label2);
txtRcvFrom = new java.awt.TextField();
txtRcvFrom.setBounds(108,72,300,24);
add(txtRcvFrom);
label3 = new java.awt.Label("Subject:");
label3.setBounds(48,96,48,24);
add(label3);
textField1 = new java.awt.TextField();
textField1.setBounds(108,96,300,24);
add(textField1);
label4 = new java.awt.Label("CC");
label4.setBounds(60,120,36,24);
add(label4);
txtCC = new java.awt.TextField();
txtCC.setBounds(108,120,300,21);
add(txtCC);
Body = new java.awt.TextArea();
Body.setBounds(60,168,400,121);
add(Body);
Reply = new java.awt.TextArea();
Reply.setBounds(60,312,404,132);
add(Reply);
cmdSend = new java.awt.Button();
cmdSend.
setActionCommand("button");
cmdSend.
setLabel("Send");
cmdSend.
setBounds(444,96,83,29);
cmdSend.
setBackground(new Color(12632256));
add(cmdSend);
//}}
Action lAction = new Action();
cmdSend.
addActionListener(lAction);
}
//{{DECLARE_CONTROLS
java.awt.Label label1;
java.awt.TextField txtMailTo;
java.awt.Label label2;
java.awt.TextField txtRcvFrom;
java.awt.Label label3;
java.awt.TextField textField1;
java.awt.Label label4;
java.awt.TextField txtCC;
java.awt.TextArea Body;
java.awt.TextArea Reply;
java.awt.Button cmdSend;
//}}
public void sendMessage(java.awt.event.ActionEvent evt)
{
String sHostName = "gatekeeper.ncic.ac.cn";
int nPort = 25;
try {
Socket sktMail = new Socket(sHostName,nPort);
PrintStream ps = new PrintStream(sktMail.getOutputStream());
ps.println("HELO " + sHostName);
Reply.appendText(getReply(sktMail) + "/n");
ps.println("MAIL FROM: " + txtRcvFrom.getText());
Reply.appendText(getReply(sktMail) + "/n");
ps.println("RCPT TO: " + txtMailTo.getText());
Reply.appendText(getReply(sktMail) + "/n");
ps.println("DATA");
Reply.appendText(getReply(sktMail) + "/n");
ps.println("From: " + "刘真人" + "/n" + "Subject: " + textField1.getText() +"/n" +
"CC: " + txtCC.getText() +"/n" + Body.getText() +"/n" + "." + "/n");
Reply.appendText(getReply(sktMail) + "/n");
ps.println("QUIT");
Reply.appendText(getReply(sktMail));
ps.close();
sktMail.close();
} catch (IOException e) {
System.out.println("Error");
}
}
String getReply(Socket sktMail)
{
try {
DataInputStream disReply = new java.io.DataInputStream(sktMail.getInputStream());
return disReply.readLine();
} catch (IOException e) {
return e.getMessage();
}
}
class Action implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == cmdSend) {
sendMessage(event);
}
}
}
}
OK,我这摸够意思吧,给你这样长的原程序。