Use applet to send e-mail source code

Source: Internet
Author: User
Tags gettext socket

is to use a component in the JBuilder,

You can go to the JBuilder catalogue,

Or use your own JDK components to change

NO 1: This program calls Foxmail to send a letter

/* This program to use a number of jbuilder classes * *


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{


/* Note Oh, here is the main code!! */


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: This program sends a letter directly:


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 ("Addressee Address:");


label2.setalignment (2);


Label2.settext ("Sender's Address:");


label3.setalignment (2);


Label3.settext ("content:");


Button1.setlabel ("send");


Button1.addactionlistener (New Mailapplet_button1_actionadapter (this));


Button2.setlabel ("clear");


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, "Mail address Error", "Your sender address error, please confirm resend!!", 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, "Mail address Error", "Your addressee address error, please confirm resend!!", 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);


/* Mail server does not authenticate readers to send SMTP is correct/


out.println ("MAIL FORM:" +sendername);


out.println ("RCPT to:" +getername);


out.println ("DATA");


Out.println (Memo);


out.println (". \nquit");


messagedialog mdlg=new Messagedialog (frame, "mail address correct", "Congratulations, your mail has been successfully sent", 1);


mdlg.show ();}


catch (Exception e) {


System.out.println (e.tostring ());


messagedialog mdlg=new Messagedialog (frame, "Send mail Failed", e.tostring (), 1);/"Mail send error, please confirm to send again!", 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.