Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i Send E-mail by applet,

 
Sultan A. A
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.*;
import java.io.*;
/* <applet code=" Email" width=400 height=60>
</applet>*/
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() ;
if(a.equals("Clear"))
{
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;
if(m==1)
m1 = 1;
else
m1=0;
}
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() ) ;
switch(m1)
{
case 0: str="Please, The Email Format is xxx@xxx.com, Try again";

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


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

break;
default: break;
}

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

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
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
arun andrew
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
have you tried Javamail API.....its very useful for sending emails...
regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic