the code for sending mail is as follows



<pre>
import java.net.*;
import java.io.*;

public class SendMail{

 String MAIL_SERVER_URL = "x.y.z.zz" ; //ur mail server ip
 int MAIL_PORT = 25; //mail server smtp port

 Socket socket;       // Socket for sending mail
 DataInputStream in;  // Input Stream from socket
 PrintStream out;     // Output Stream for socket
 String str;          // for reading server comments


SendMail(String to, String from, String subject, String message) throws
ProtocolException, IOException{

  Socket socket = new Socket(MAIL_SERVER_URL, MAIL_PORT);

  in     = new DataInputStream(socket.getInputStream());
  out    = new PrintStream(socket.getOutputStream());


  if(!checkStatus("220")) throw new ProtocolException(str);

  out.println( "HELO " + MAIL_SERVER_URL );
  out.flush() ;
  if(!checkStatus("250")) throw new ProtocolException(str);

      out.println( "MAIL FROM: " + from );
      out.flush() ;
      if(!checkStatus("250")) throw new ProtocolException(str);

      out.println( "RCPT TO: " + to );
      out.flush() ;
     if(!checkStatus("250")) throw new ProtocolException(str);

     out.println( "DATA" );
     out.flush() ;
  if(!checkStatus("354")) throw new ProtocolException(str);

     out.println("From: " + from);
     out.println("To: " + to);
     out.println( "Subject: " + subject + "\n" );
     out.flush() ;

     out.println("Comment: Unauthenticated sender");
     out.println("X-Mailer: Simple tSmtp");
     out.println("");
     out.println( message ) ;
     out.println(".") ;
     out.flush() ;
     if(!checkStatus("250")) throw new ProtocolException(str);


      out.println("QUIT");
      out.flush();

      in.close();
      socket.close();

 }


 private boolean checkStatus(String RFC)throws ProtocolException,
IOException{

        str = in.readLine();
        System.out.println(str);

     if (!str.startsWith(RFC))    throw new ProtocolException(str);

      while (str.indexOf('-') == 3) {
          str = in.readLine();
          if (!str.startsWith("RFC"))  throw new ProtocolException(str);
   }

   return true;
 }



}

</pre>


Njoy,

Tripat


----- Original Message -----
From: "Mohankarthikeyan.K,AMB Chennai." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, November 13, 2000 4:38 PM
Subject: Re: sending mails through servlets


> refer professional java server programming . Full source code is
available.
>
> > -----Original Message-----
> > From: A.R.Karthikeyan [SMTP:[EMAIL PROTECTED]]
> > Sent: Monday, November 13, 2000 4:11 PM
> > To:   [EMAIL PROTECTED]
> > Subject:      Re: sending mails through servlets
> >
> > hi,
> > I am new to Servlet Programming  and I have been assigned a Project
where
> > by
> > the Servlet Program  has to to capture all the parameters pertaining to
a
> > customer feedback form and send the parameters and their values as an
> > email
> > to a common office email id over the LAN having an Exchange server.
> > Can anybody provide me with some tips as well as the classes that can be
> > used- for the above mentioned task.
> >
> > Karthikeyan A.R
> >
> >
__________________________________________________________________________
> > _
> > 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
>

___________________________________________________________________________
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