Hi  Baris ,

Use this class ----->

// Class MailServlet for sending mail
// It's a stand alone class
// Taken from O'reilly

import java.io.*;
import java.util.*;
import java.net.InetAddress;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.math.*;
import java.io.*;
import java.util.*;
import sun.net.smtp.SmtpClient;

public class MailServlet
{
        private HttpServletRequest req;
    private HttpServletResponse res;
    private String strEmail="", strSub="", strData="";
        //Constructor ---------
        public MailServlet(HttpServletRequest lreq, HttpServletResponse lres, String
strMail,
                                      String strMailData, String strSubject)
    {
                try
        {
                        req = lreq;
                res = lres;
                strEmail = strMail;
                                strData = strMailData;
                strSub = strSubject;
                serv(req, res);
        }
        catch(IOException e){}
    }
        // Method serv ------------
    public void  serv ( HttpServletRequest req, HttpServletResponse res)
                                                throws IOException
    {
                ServletOutputStream out = res.getOutputStream();
        res.setContentType("text");
        String email            = strEmail  ;
                String emailFrom        = "xxx.com";
        boolean succeed         = false;
        PrintStream ps          = null;
        SmtpClient sendmail = null;

        if (email.length() > 0)
                {
                try {
                //open smtp connection(* one of these two must be commented)
                //sendmail = new SmtpClient("xxx");
                        sendmail = new SmtpClient("xxx.com");
                        sendmail.from(emailFrom);
                        sendmail.to(email);

                //get printstream
                        ps = sendmail.startMessage();

                                //set succed to true
                        succeed = true;
                }catch (Exception e) {
                        //System.out.println("Error :" + e.toString());

                }// end of try - catch block

                                // if failed to send an e-mail
                if (!succeed)
                {
                        try
                        {
                    // open smtp connection
                        sendmail = new
SmtpClient(InetAddress.getLocalHost().getHostName());
                        sendmail.from(emailFrom);
                        sendmail.to(email);

                    // get printstream
                        ps = sendmail.startMessage();
                                        }catch (Exception e) {
                        //System.out.println("Error :" + e.toString());

                    //if we bomb this time, give up
                        return;
                        }
            } // end of second nested if

            try
            {

                        // send headers.
                ps.println("From: "+emailFrom);
                ps.println("To: "+email);
                ps.println("Subject:  "+strSub);
                ps.print("\r\n");  //header area delimiter

                        // now send data to it
                ps.println(strData);
                ps.flush();
                ps.close();
                sendmail.closeServer();
            }catch (Exception ignored) {
                return;
            } // end of try-catch block
        }// end of first if

    } // end of method serv

} // end of class MailServlet

------>
If you find any problem, mail to me..
Have fun......take care,

Sujoy


____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1

___________________________________________________________________________
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