English 中文(简体)
Jetty JNDI Java Mail
原标题:

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

最佳回答

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

问题回答

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>




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签