You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Eulogio Robles <eu...@mi.cl> on 2003/08/07 20:42:39 UTC

Problems with Javamail and taglib on Tomcat

I have two pages (mailer1.jsp and mailer2.jsp). Both are almost identical : they receive four parameters (to, from, 
subject and message), and generate an email message using Javamail.

mailer1.jsp uses a JSP scriplet, invoking standard Java Mail API calls to send the message.
mailer2.jsp uses taglib-mailer and taglib-request and a JNDI mail session resource.

When I use mailer1, all messages go out without problems.

The problem is, when I use mailer2.jsp, the first message goes out to the intended recipient. Any message that is sent 
from there, even from other users on different PC's, go to the same first recipient, no matter what address is 
specified by each user. All the rest (subject and message body) is different for each message. Only the original first 
recipient is "shared" by all sessions.

The JNDI resource is defined on the application context on server.xml, as follows :

    <Resource name="mail/mi-mail" scope="Unshareable" type="javax.mail.Session"/> //it was "shareable", same result
    <ResourceParams name="mail/mi-mail">
      <parameter>
        <name>mail.smtp.host</name>
        <value>my-mail-host</value>
      </parameter>
    </ResourceParams>

and this is the taglib sender code on mailer2.jsp :

<%@taglib uri="/WEB-INF/taglibs-mailer.tld" prefix="mt"%>
<%@page session="true" isThreadSafe="true" errorPage="/errorpage.jsp" isErrorPage="false"%>
<%@taglib uri="/WEB-INF/taglibs-request.tld" prefix="req"%>
....
    <mt:mail session="java:/comp/env/mail/mi-mail">
        <req:existsParameter name="to">
          <mt:setrecipient type="to"><req:parameter name="to"/></mt:setrecipient>
        </req:existsParameter>
        <req:existsParameter name="from">
          <mt:from><req:parameter name="from"/></mt:from>
        </req:existsParameter>
        <req:existsParameter name="cc">
          <mt:setrecipient type="cc"><req:parameter name="cc"/></mt:setrecipient>
        </req:existsParameter>
        <req:existsParameter name="subject">
          <mt:subject><req:parameter name="subject"/></mt:subject>
        </req:existsParameter>
        <req:existsParameter name="message">
          <mt:message><req:parameter name="message"/></mt:message>
        </req:existsParameter>
        <mt:send>
          <p>The following errors occured<br/><br/>
          <mt:error id="err">
            <jsp:getProperty name="err" property="error"/><br/>
          </mt:error>
          <br/>Please back up a page, fix the error and resubmit.</p>
        </mt:send>
     </mt:mail>

I first noticed the problem, because I have a page (a form) that calls a second page that must generate two separate 
mail messages, with different texts for two separate recipients. It calls mailerX.jsp twice, via two separate 
<jsp:include> directives. When I include mailer2, both messages are delivered to whatever user first invoked it 
(mailer2) on some session. Both messages are indeed different, each one with its own subject and body. On the other 
hand, mailer1.jsp correctly delivers each message to each intended user.

I am using Apache 2 and Tomcat 4 (all latest versions).

Any ideas?

Thanks in advance,

Eulogio Robles


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