hi

i have written the following code using the Java Mail API which allows one
to send email using a servlet.
you will require the following two files
1.  mail.jar - available with the Java Mail API
2.  activation.jar - available with Java Activation Framework

this is the code :

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class Formmail extends HttpServlet {

        public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
                res.setContentType("text/html");
                PrintWriter out = res.getWriter();

                out.println("<HTML><HEAD></HEAD>");
                out.println("<BODY>Email has been sent</BODY></HTML>");

                boolean debug = false; // change to get more infomation

                //  set the host
                Properties props = new Properties();
                props.put("mail.smtp.host", "192.168.0.15");

                // create some properties and get the default Session
                Session session = Session.getDefaultInstance(props, null);
                session.setDebug(debug);


                try {
                        // create a message
                        Message msg = new MimeMessage(session);

                        // set the from
                        InternetAddress from = new
InternetAddress("[EMAIL PROTECTED]");
                        msg.setFrom(from);

                        InternetAddress[] address = {new
InternetAddress("[EMAIL PROTECTED]")};
                        msg.setRecipients(Message.RecipientType.TO,
address);
                        msg.setSubject("test message");

                        String msgText;
                        msgText = "this is a test message";
                        msg.setContent(msgText, "text/plain");

                        Transport.send(msg);




                } catch (MessagingException mex) {
                                mex.printStackTrace();
                }


        }

}


regards

manoj mansukhani



----- Original Message -----
From: George Ter-Saakov <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 02, 1999 6:07 PM
Subject: Email from servlet.


> Does anybody have something free which can help to send email.
>
> Thanks
> George.
>
>
___________________________________________________________________________
> 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