用APPLET发送E-MAIL的源代码
时间:2011-01-22
都要用到JBuilder里的一个组件,
你可以去JBuilder目录下拷,
或自己用JDK的组件改一下
NO 1:这个程序调用Foxmail发送信件
/*这个程序要用到Jbuilder的几个类*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import java.net.*;
public class EmailApplet extends Applet{
Button button;
TextField textField;
public EmailApplet(){}
public void init(){
try{
jbInit();}
catch(Exception e){
e.printStackTrace();}
}//end of init()
public void jbInit()throws Exception{
setLayout(new BorderLayout());
button=new Button("sendMail");
textField=new TextField();
add("North",textField);
add("South",button);
}//end of jbInit()
public boolean action(Event e,Object arg){
if(arg.equals("sendMail")){
try{
/*注意哦,这里是主要代码!!*/
String mailto=textField.getText();
URL url=new URL(mailto);
AppletContext ac=this.getAppletContext();
ac.showDocument(url);}
catch(Exception e2){
System.out.println(e2.toString());}
}//end of if
else{
return super.action(e,arg);}
return true;
}//end of action()
}//end of EmailApplet
NO 2:这个程序直接发送信件:
import borland.jbcl.layout.*;
import borland.jdbl.*;
import java.awt.*;
import java.applet.Applet;
import java.util.StringTokenizer;
import java.net.Socket;
import java.io.PrintStream;
import java.lang.Exception;
import java.awt.event.ActionEvent;
public class MailApplet extends Applet{
boolean isStandalone=false;
PaneLayout panelLayout1=new PaneLayout();
panel panel1=new Panel();
Label label1=new Label();
XYLayout xYLayout1=new XYLayout();
Label Label2=new Label();
TextField textField1=new TextField();
TextField textField2=new TextField();
Label lable3=new Label();
TextArea textArea1=new TextArea();
Button button1=new Button();
Button button2=new Button();
private int SMTP_PORT=25;
Frame frame=new Frame();
Color bgcolor=null;
String send="";
String get="";
public MailApplet(){}
public void init(){
try{
int c1=Integer.parseInt(getParameter("color1"));
int c2=Integer.parseInt(getParameter("color2"));
int c3=Integer.parseInt(getParameter("color3"));
bgcolor=new Color(c1,c2,c3);
SMTP_PORT=Integer.parseInt(getParameter("port"));
send=getParameter("send");
get=getParameter("get");
jbInit();}
catch(Exception e){
e.printStackTrace();}
}//end of init()
/*Component initialization*/
private void jbInit()throws Exception{
this.setSize(new Dimension(332,280));
panel1.setBackground(bgcolor);
label1.setAlignment(2);
label1.setText("收信人地址:");
label2.setAlignment(2);
label2.setText("寄信人地址:");
label3.setAlignment(2);
label3.setText("内容:");
button1.setLabel("发 送");
button1.addActionListener(new MailApplet_button1_actionAdapter(this));
button2.setLabel("清 除");
button2.addActionListener(new MailApplet_button2_actionAdapter(this));
panel1.setLayout(xYL
|