hope this one helps.

Molly

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.mail.*;
import javax.mail.Message;
import javax.mail.event.*;
import javax.mail.internet.*;


public class MailClient extends Frame {
 String mailHost = "mail.dpmllc.com";
 Label toLabel = new Label("To:");
 Label fromLabel = new Label("From:");
 Label subjectLabel = new Label("Subject:");
 Label contentLabel = new Label("Content:");
 Label statusLabel = new Label("Status:");
 TextField destination = new TextField();
 TextField source = new TextField();
 TextField subject = new TextField();
 TextArea content = new TextArea();
 Button send = new Button("Send Message");
 TextArea status = new TextArea();
public static void main(String args[]){
  MailClient app = new MailClient();
 }
public MailClient() {
  super("MailClient");
  setup();
  addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e) {
                        System.exit(0);
                }
        });
  setSize(550,450);
  show();
 }
void setup() {
  setupMenuBar();
  layoutComponents();
  send.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e) {
                sendMessage();
  }
  });
 }
void setupMenuBar() {
  MenuBar menuBar = new MenuBar();
  Menu fileMenu = new Menu("File");
  MenuItem fileExit = new MenuItem("Exit");
//  fileExit.addActionListener(new MenuItemHandler());
  fileMenu.add(fileExit);
  menuBar.add(fileMenu);
  setMenuBar(menuBar);
 }
void layoutComponents() {
  int x = 10;
  int y = 50;
  // Set bounds
  toLabel.setBounds(x,y,50,25);
  destination.setBounds(x+70,y,300,25);
  fromLabel.setBounds(x,y+40,50,25);
  source.setBounds(x+70,y+40,300,25);
  subjectLabel.setBounds(x,y+80,50,25);
  subject.setBounds(x+70,y+80,300,25);
  contentLabel.setBounds(x,y+120,50,25);
  content.setBounds(x+70,y+120,300,100);
  statusLabel.setBounds(x,y+240,50,25);
  status.setBounds(x+70,y+240,300,100);
  send.setBounds(400,y,100,30);
  // Add components
  add(toLabel);
  add(destination);
  add(send);
  add(fromLabel);
  add(source);
  add(subjectLabel);
  add(subject);
  add(contentLabel);
  add(content);
  add(statusLabel);
  add(status);
  add(new Label(""));
 }
 void sendMessage() {
  Properties properties = new Properties();
  properties.put("mail.smtp.host",mailHost);
  properties.put("mail.from",source.getText());
  Session session = Session.getInstance(properties, null);
  try {
   Message message = new MimeMessage(session);
   InternetAddress[] address =
    {new InternetAddress(destination.getText())};
   message.setRecipients(Message.RecipientType.TO, address);
   message.setFrom(new InternetAddress(source.getText()));
   message.setSubject(subject.getText());
   message.setContent(content.getText(),"text/plain");
   Transport transport = session.getTransport(address[0]);
   transport.addConnectionListener(new ConnectionHandler());
   transport.addTransportListener(new TransportHandler());
   transport.connect();
   transport.sendMessage(message,address);
  } catch (NoClassDefFoundError ne)
     {
      status.setText(ne.toString());
     }
   catch(Exception e){
   status.setText(e.toString());
  }
 }
 class ConnectionHandler extends ConnectionAdapter {
  public void opened(ConnectionEvent e) {
   status.setText("Connection opened.");
  }
   public void disconnected(ConnectionEvent e) {
   status.setText("Connection disconnected.");
  }
  public void closed(ConnectionEvent e) {
   status.setText("Connection closed.");
  }
 }

  class TransportHandler extends TransportAdapter {


     }

}




-----Original Message-----
From: Rajiv Bhatnagar [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 03, 2000 8:01 AM
To: [EMAIL PROTECTED]
Subject: Sending email from Servlet


Friends,

I have in my application feature of sending email to the person who has
registered with us. I have a registeration servlet which does all the work
and also strong all the required in the database . The email-id of the
person is a part of that. I want to add this funtionality to send email from
this servlet as soon as the transaction regarding registeration is commited.
I want to use the javamail api for this but really have no clue how to
start. Can anybody help me with some demo/example . The examples i tried
looking were complex like storing email, managing folders. I just want to
send the email and that's all.

I will appreciate any type of help.

Rajiv.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to