tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Tomcat & JavaMail Help
Date Mon, 20 Feb 2006 18:49:18 GMT
Hi all,

I am trying to send an email from a servlet. The application is running
on Windows 2003. The servlet compiles but it does not send any email.
My smtp server is configured to properly accept and relay message from
the machine on which my application is running (tested with another
email sending utility). The Tomcat log files do not show anything wrong.
I have an html form that posts the "fromEmail" and "toEmail" to the
FormProcessing servlet. Please find the servlet code below. 

import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.mail.*;
import javax.mail.internet.*;

public class FormProcessor extends HttpServlet{
   public void doPost(HttpServletRequest request, HttpServletResponse
	   String fromEmail = request.getParameter("fromEmail");
	   String toEmail = request.getParameter("toEmail");
		   Context initCtx = new InitialContext();
		   Context envCtx = (Context) initCtx.lookup("java:comp/env");
		   Session session = (Session) envCtx.lookup("mail/Session");
		   Message message = new MimeMessage(session);
		   message.setFrom(new InternetAddress(fromEmail));
		   message.addRecipient(Message.RecipientType.TO, new
		   message.setSubject("Hello JavaMail");
		   message.setText("NK Welcomes you to JavaMail");
	   }catch(Exception e){
	   log("Error in writing response", e);

Please note that I have added the following xml file

which contains:
<Context path='/nsb' docBase='nsb' debug='0' privileged='true'>
  <Resource name='mail/Session' auth='Container'
  <ResourceParams name='mail/Session'>

I have also added the following to the web.xml file


Your help will be greatly appreciated.
Thanks in advance.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message