/* $Id: SendMailServlet.java,v 1.1 2001/09/09 04:00:08 craigmcc Exp $ * */ import java.io.IOException; import java.io.PrintWriter; import javax.mail.Message; import javax.mail.*; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.naming.Context; import javax.naming.InitialContext; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Example servlet sending mail message via JNDI resource. * * @author Craig McClanahan * @version $Revision: 1.1 $ $Date: 2001/09/09 04:00:08 $ */ public class SendMailServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Acquire request parameters we need String from = request.getParameter("mailfrom"); String to = request.getParameter("mailto"); String subject = request.getParameter("mailsubject"); String content = request.getParameter("mailcontent"); if ((from == null) || (to == null) || (subject == null) || (content == null)) { RequestDispatcher rd = getServletContext().getRequestDispatcher("/sendmail.html"); rd.forward(request, response); return; } // Prepare the beginning of our response PrintWriter writer = response.getWriter(); response.setContentType("text/html"); writer.println(""); writer.println("
"); writer.println(""); t.printStackTrace(writer); writer.println(""); writer.println(""); } // Prepare the ending of our response writer.println("