This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how can i Send E-mail by applet, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how can i Send E-mail by applet," Watch "how can i Send E-mail by applet," New topic

how can i Send E-mail by applet,

Sultan A. A

Joined: Sep 30, 2004
Posts: 4
I am try to make an applet to send E-mail, and I make text field for email,

Now, I want to check this email is in correct form XXX@XXX.XXX or not

either Yes or No should I get dialog message. but when I write this applet
I faced problem in dialog message, how can I solve it.

this is the Code :

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/* <applet code=" Email" width=400 height=60>
public class Email extends Applet implements ItemListener, ActionListener, TextListener{
TextArea ta;
TextField tf;
Button b,c;
String Ch="";
Image flag;
String char1="",a="",tf_Email;
int n = 0;
int m = 0;
int m1 = 0;
sendEmail se;

public void init(){
ta= new TextArea(15,50) ;
add(ta) ;

tf = new TextField(30) ;
add(tf) ;

label = new Label("E-mail :") ;
add(label) ;

l = new Label("Your Messege :") ;
add(l) ;

Panel p = new Panel() ;

b = new Button("Send") ;
b.addActionListener(this) ;
p.add( b ) ;

c = new Button("Clear") ;
c.addActionListener(this) ;
p.add( c ) ;
add(p,"South") ;

setLayout ( new GridBagLayout()) ;
GridBagConstraints gbc = new GridBagConstraints() ;
gbc.fill = GridBagConstraints.NONE;gbc.anchor = GridBagConstraints.CENTER;
gbc.weightx = 1;
gbc.weighty = 0;
addUsingGBL ( ta, gbc, 1,2,0,1) ;
addUsingGBL ( tf, gbc, 0,0,2,1) ;
addUsingGBL ( l, gbc, 0,1,1,1) ;
addUsingGBL ( p, gbc, 0,3,2,1) ;

void addUsingGBL (Component comp, GridBagConstraints gbc, int x, int y, int w, int h) {
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
add(comp, gbc) ;

public void paint(Graphics g)
public void itemStateChanged( ItemEvent ie){
public void actionPerformed( ActionEvent ae){
a = ae.getActionCommand() ;
ta.setText("") ;
else if(a.equals("Send"))
Semail() ;
public void textValueChanged(TextEvent te){


public void Semail(){

tf_Email = tf.getText() ;

for(int i=0;i<tf_Email.length();i++){
if(tf_Email.charAt(i) == '@')
m = 1;
m1 = 1;
se = new sendEmail() ;
se.setVisible(true) ;
se .setSize(310,180) ;

public class sendEmail extends Frame implements ActionListener
String str=" ";
Button b3;
private sendEmail()
super( " Message For The User" ) ;
setLayout( new FlowLayout() ) ;
case 0: str="Please, The Email Format is, Try again";

case 1: str=" Thank You Very Much For Subscribing ";

case 4: str="Thank For Adding Your Opinion ";

default: break;

Label le = new Label(str+"\n") ;

b3 = new Button( "OK" ) ;
b3.addActionListener( this ) ;
add( b3 ) ;

addWindowListener( new WindowAdapter()
public void windowClosing( WindowEvent we ) {
dispose() ;
}) ;

public void actionPerformed( ActionEvent aee )
dispose() ;
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Short Answer: You can't

One of the constraints of the "Applet Sandbox" is that you can only connect back to the machine from which the applet was downloaded. This constraint can be overcome with signed applets or by getting the user to alter their security policy.

This is a good thing. It means that I, the user, can feel confident that, if I download and run someone else's applet, it won't turn my PC into a spam monster while I'm using it.

A better solution would be to do any emailing from the server using a Servlet. There are plenty of articles on the javamail api out there. A google search is the best way to find them.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
arun andrew

Joined: Dec 21, 2004
Posts: 7
have you tried Javamail API.....its very useful for sending emails...
I agree. Here's the link:
subject: how can i Send E-mail by applet,
It's not a secret anymore!