On Wed, 2012-01-11 at 05:54 -0800, Thom Hehl wrote:
> This has been very helpful, thank you. I had been unable to find this:
>
> One other question, my spring configuration for this looks like this:
>
> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
> <property name="host" value="smtp.xxxx.com"/>
> <property name="password" value="xxxxx"/>
> <property name="port" value="587"/>
> <property name="username" value="noreply@xxxxx.com"/>
> <property name="javaMailProperties">
> <props>
> <prop key="mail.smtp.from">noreply@xxxx.com</prop>
> <prop key="mail.smtp.user">noreply@xxxx.com</prop>
> <prop key="mail.smtp.auth">true</prop>
> <prop key="mail.smtp.starttls.enable">true</prop>
> </props>
> </property>
> </bean>
>
> How do I place the properties for javaMailProperties in?
There are two ways that you can do this:
1.) You can put String values into JNDI with the <Environment/> tag.
https://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html#Environment_Entries
You would then need to use Spring to pull each String value from JNDI.
This would be a bit tedious if you need to specify more than one or two
values.
2.) Alternatively, you could configure a complete Java Mail Session with
Tomcat.
https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JavaMail_Sessions
Then load the Session from JNDI with Spring and pass the session to your
org.springframework.mail.javamail.JavaMailSenderImpl bean, rather than
specifying individual properties.
>From the JavaMailSenderImpl Java Docs:
"Allows for defining all settings locally as bean properties.
Alternatively, a pre-configured JavaMail Session can be specified,
possibly pulled from an application server's JNDI environment."
http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/mail/javamail/JavaMailSenderImpl.html
Dan
>
> -----Original Message-----
> From: Daniel Mikusa [mailto:dmikusa@vmware.com]
> Sent: Wednesday, January 11, 2012 8:29 AM
> To: Tomcat Users List
> Subject: Re: Context configuration file
>
> On Wed, 2012-01-11 at 05:01 -0800, Thom Hehl wrote:
> > We are using a context configuration file to provide our database
> > connectivity through a JNDI entry to our application so that the file
> > can change without the purchasers of our software having to tinker about
> > with it internally. Here is our file:
> >
> >
> >
> > <Context path="/chronicle" debug="5" reloadable="true"
> > crossContext="true">
> >
> >
> >
> > <Logger className="org.apache.catalina.logger.FileLogger"
> > prefix="ej-Log." suffix=".txt" timestamp="true"/>
> >
> > <Resource name="jdbc/chronicle"
> >
> >
> > auth="Container"
> >
> > type="javax.sql.DataSource"
> >
> > username="sa"
> >
> > password="xxxxxxx"
> >
> >
> > driverClassName="net.sourceforge.jtds.jdbc.Driver"
> >
> >
> > url="jdbc:jtds:sqlserver://localhost/PsDb"
> >
> >
> > maxActive="-1"
> >
> >
> > maxIdle="0"
> >
> > />
> >
> > </Context>
> >
> >
> >
> > I picked this trick up from a predecessor on a job and have never found
> > it documented anywhere.
>
> I'm not exactly sure what you mean here, but JNDI (i.e. the <Resource/>
> tag) is document here.
>
> https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
>
> and here.
>
> https://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html
>
> > I would like to use the same approach to define
> > JNDI keys for the mail server. Can someone help?
>
> You can certainly do this. Here's a link to the docs which describes
> how to define Mail Sessions.
>
> https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JavaMail_Sessions
>
> Dan
>
|