tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngues...@kouame.us
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 java.io.*;
import javax.naming.*;
import javax.mail.*;
import javax.mail.internet.*;

public class FormProcessor extends HttpServlet{
   public void doPost(HttpServletRequest request, HttpServletResponse
response){
	   String fromEmail = request.getParameter("fromEmail");
	   String toEmail = request.getParameter("toEmail");
	   try{
		   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
InternetAddress(toEmail));
		   message.setSubject("Hello JavaMail");
		   message.setText("NK Welcomes you to JavaMail");
		   Transport.send(message);
	   }catch(Exception e){
	   log("Error in writing response", e);
	   }
   	}
}


Please note that I have added the following xml file

 $CATALINA_HOME/conf/Catalina/localhost/nsb.xml
which contains:
<Context path='/nsb' docBase='nsb' debug='0' privileged='true'>
  <Resource name='mail/Session' auth='Container'
type='javax.mail.Session'/>
  <ResourceParams name='mail/Session'>
     <parameter>
        <name>mail.smtp.host</name>
	<value>mailgate1.sainc.com</value>
     </parameter>
  </ResourceParams>
</Context>

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

<resource-ref>
       <res-ref-name>mail/Session</res-ref-name>
       <res-type>javax.mail.Session</res-type>
       <res-auth>Container</res-auth>
    </resource-ref>


Your help will be greatly appreciated.
Thanks in advance.

N'guessan


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message