爱心技术专栏专题

这是个用APPLET发送E-MAIL的源代码

摘录:爱心 来源:爱心 加入时间:2006年09月14日
摘要:
这是个用APPLET发送E-MAIL的源代码
都要用到JBuilder里的一个组件,
你可以去JBuilder目录下拷,
或自己用JDK的组件改一下

NO 1:这个程序调用Foxmail发送信件

/*这个程序要用到Jbuilder的几个类*/

import java.awt.*;
import java.awt.event.*;
import …

转载:转载请保留本信息,本文来自
http://www.51dibs.com
/html/2006/article/info/a_b344100f85046e51.htm

这是个用APPLET发送E-MAIL的源代码

站点:爱心种子小博士 关键字:这是个用APPLET发送E-MAIL的源

   
这是个用APPLET发送E-MAIL的源代码
都要用到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(xYLayout);

this.setLayout(panelLayout1);
thsi.add(panel1,new PaneConstraints("panel1","panel1",PaneConstraints.ROOT,1.0f));

panel1.add(label1,new XYConstraints(10,5,80,20));
panel1.add(label2,new XYConstraints(10,30,80,20));
panel1.add(textField1,new XYConstraints(95,5,200,20));
panel1.add(textField2,new XYConstraints(95,30,200,20));
panel1.add(label3,new XYConstraints(10,60,80,20));
panel1.add(textArea1,new XYConstraints(10,80,300,150));
panel1.add(button1,new XYConstraints(50,240,80,25));
panel1.add(button2,new XYConstraints(160,240,80,25));

textField1.setText(get);
textField2.setText(send);
}//end of jbInit()

public String getAppletInfo(){
return "Applet Information";}


public String[][] getParameteInfo(){
return null;}

void sendMail(){
String sender=textField2.getText();
String geter=textField1.getText();
String memo=textArea1.getText();
StringTokenizer st=new StringTokenizer(sender,"@");
int count=st.countTokens();
if(count!=2){
MessageDialog mdlg=new MessageDialog(frame,"邮件地址错误","你的发信人地址错误,请确认后重新发送!!",1);
mdlg.show();
textField2.selectAll();
return;}
String senderName=st.nextToken();
String senderHost=st.nextToken();
st=new StringTokenizer(geter,"@");
count=st.countTokens();
if(count!=2){
MessageDialog mdlg=new MessageDialog(frame,"邮件地址错误","你的收信人地址错误,请确认后重新发送!!",1);
mdlg.show();
textField1.selectAll();
return;}
String geterName=st.nextToken();
String geterHost=st.nextToken();
try{
Socket s=new Socket(geterHost,SMTP_PORT);
PrintStream out=new PrintStream(s.getOutputStream());
out.println("HELLO:"+senderHost);
/*邮件服务器不认证读者所输SMTP是否正确*/
out.println("MAIL FORM:"+senderName);
out.println("RCPT TO:"+geterName);
out.println("DATA");
out.println(memo);
out.println(".\nQUIT");
MessageDialog mdlg=new MessageDialog(frame,"邮件地址正确","恭喜,您的邮件已经成功发送",1);
mdlg.show();}
catch(Exception e){
System.out.println(e.toString());
MessageDialog mdlg=new MessageDialog(frame,"邮件发送失败",e.toString(),1);//"邮件发送出错,请确认合重新发送!",1);
mdlg.show();
return;}
}//end of sendMail()

void button1_actionPerformed(ActionEvent e){
sendMail();
textArea1.setText("");}

void button2_actionPerformed(ActionEvent e){
textField1.setText("");
textFIeld2.setText("");
textArea1.setText("");}

}//end of MailApplet

class MailApplet_button1_actionAdapter implements java.awt.event.ActionListener{
MailApplet adaptee;
MailApplet_button1_actionAdapter(MailApplet adaptee){
this.adaptee=adaptee;}

public void actionPerformed(ActionEvent e){
adaptee.button1_actionPerformed(e);}
}//end of this

class MailApplet_button2_actionAdapter implements java.awt.event.ActionListener{
MailApplet adaptee;
MailApplet_button2_actionAdapter(MailApplet adaptee){
this.adaptee=adaptee;}
public void actionPerformed(ActionEvent e){
adaptee.button2_actionPerformed(e);}
}//end of this

客户服务中心信箱:[email protected] [email protected] 网站地图

声明

合作伙伴: