分享
 
 
 

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

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

都要用到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(". QUIT");

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有