Hi there
 following is a sample code for sending mails thru servlet
HTH
Abhishek



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

  it   requires a direct internet connection (no firewalls), or a mailserver
  running on the webserver's host machine.

public class MailServlet extends HttpServlet {
    public void service(HttpServletRequest req, HttpServletResponse res)
        throws IOException
    {
        Enumeration keys;
        String key;
        String value;
        String line = null;

        res.setContentType("text/html");
        PrintWriter out = res.getWriter();

      out.println("<HEAD></HEAD><BODY>");



        out.println("<h1> Form Reply </h1>");
        out.println("<p>");

        String name = req.getParameter("name");
        String email = req.getParameter("e-mail");
        PrintStream ps = null;
    SmtpClient sendmail = null;
        if ((name.length() > 0) && (email.length() > 0)) {
            try {

                  sendmail = new SmtpClient("your mails server address");
                sendmail.from("your mail address");
                  sendmail.to(email);
                 ps = sendmail.startMessage();

                    ps.println("From: "+email);
                    ps.println("To: "+email);
                    ps.println("Subject: Thanks for Shopping");
                    ps.print("\r\n");

                    ps.println("Hello " + name + ",");
                    ps.println();

                    ps.flush();
                    ps.close();
                    sendmail.closeServer();
return;
} catch (Exception e) {
                    e.printStackTrace();
                    out.println("There was an error sending you mail.");
                       out.println("</BODY>");
                        out.flush();

                    return;
                }
        }


    }
}




> -----Original Message-----
> From: Jin-Ru Ong [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, June 12, 2000 3:31 PM
> To:   [EMAIL PROTECTED]
> Subject:      Need help sending email from servlet
>
> Hi all,
> Forgive me if this is a stupid question, but how do you write a servlet
> to send email on Windows machines?
>
> I am running JSWDK-1.0.1 on a Win NT 4.0 workstation and I need to write
> a servlet that will email a particular user with feedback comments from
> the form.
>
> *I cannot telnet port 25 (SMTP) on my workstation, it runs on MS
> Exchange mail.
>
> Sorry if this is a newbie question, I'm new to Java servlets and am
> trying to write my first simple app!
>
> Any help much appreciated.
>
> __________________________________________________________________________
> _
> 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