views:

394

answers:

2

Hi all,

I am using Jetty 7 with JBoss Seam and have 2 Java Mail Sessions configured, one for support notifications and another for general notifications.

The problem I am having appears to be from JBoss Seam / JSF not being able to resolve the session which I set in the Event Context to the proper Java Mail Session prior to sending the email.

Since it cannot resolve the session, it defaults to localhost on port 25. The strange thing is, I am using the same code to set the session as before, I am just getting it from JNDI now as opposed to a Seam component.

I am guessing that the problem is from getting the Session from JNDI and something isn't being proxied properly.

How do most places setup email notifications in a web application, do you often support more than 1, if so, what does your configuration look like?

Walter

A: 

Have you tried this (from the documentation):

<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="mail" class="org.mortbay.jetty.plus.naming.Resource">
     <Arg><Ref id="wac"/></Arg>
     <Arg>mail/Session</Arg>
     <Arg>
       <New class="org.mortbay.naming.factories.MailSessionReference">
         <Set name="user">fred</Set>
         <Set name="password">OBF:1xmk1w261z0f1w1c1xmq</Set>
         <Set name="properties">
           <New class="java.util.Properties">
             <Put name="mail.smtp.host">XXX</Put>
             <Put name="mail.from">me@me</Put>
             <Put name="mail.debug">true</Put>
           </New>
          </Set>
       </New>
     </Arg>
</New>
</Configure>
David Rabinowitz
David, I tried exactly that, but to no avail. I'm using Jetty 7 so I changed the classnames to the Jetty7 equivalent. I am not passing in a web application context so I'm guessing my components may be available to other applications (if I had others). When I debug, this session is in JNDI otherwise it would throw an exception. Both the user/password are empty in PasswordAuthenticator. While the properties passed in with the mail session are exactly as I set, none of them appear to be actually used.Walter
David, I updated the question above. I was getting the Java Mail Session back as expected although not everything was populated. When Seam tried to render the message, that is when it could not find the session resulting in the appearance of the properties not sticking.
A: 

Hmm, the problem was between my module and JBoss Seam. Again, I was doing something that was non-standard (like using more than 1 email address in the application, and dynamically assign the mail session based on the from address).

Essentially what happened was I parsed the email for the from address, then using that, looked up the mail session in JNDI. With that mail session, I set it in the active event context, then JBoss Seam automatically looks for the "session" value binding in the email:

...

I had several issues with this, the mailSessionGoesHere must not be named session. For some odd reason, that conflicts with another component. Also, because I was sending the email asynchronously, it had its own event context which meant, I needed to pass it in a map and not set it directly in the event context that was used to trigger the email.

Once I sorted all that out, I can now send email from whatever address I choose as long as its setup in web.xml, jetty-env.xml, and the email template of course.

Walter