You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Lau, Alex" <al...@ballard.com> on 2013/03/15 16:33:35 UTC

mail/Session resources lookup fail

I have a typical mail resource set up but my lookup always returns localhost as the smtp host.

My webapp contect.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<context>
<Resource name="mail/Session" auth="Container" type="javax.mail.Session" mail.smtp.host="smtp.mydomain.com" mail.debug="true"></Resource>
</context>

My webapp web.xml has an entry like this:

<resource-ref>
    <description>Resource reference to a factory for javax.mail.Session instances that may be used for sending electronic mail messages, preconfigured to connect to the appropriate SMTP server.</description>
    <res-ref-name>mail/Session</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

My webapp code

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
javax.mail.Session msession = (javax.mail.Session) envCtx.lookup("mail/Session");
System.out.println("msession to string is " + msession.getProperty("mail.smtp.host"));

For some reasons, this work on my Eclipse/Tomcat set up but when I deploy everything to another server, the getProperty always return localhost as the smtp host. I search for all Tomcat log files but could not find anything.

Any ideas?

Thanks in advance!


Alex


Re: mail/Session resources lookup fail

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/3/15 Lau, Alex <al...@ballard.com>:
> I have a typical mail resource set up but my lookup always returns localhost as the smtp host.
>
> My webapp contect.xml looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <context>
> <Resource name="mail/Session" auth="Container" type="javax.mail.Session" mail.smtp.host="smtp.mydomain.com" mail.debug="true"></Resource>
> </context>
>
> My webapp web.xml has an entry like this:
>
> <resource-ref>
>     <description>Resource reference to a factory for javax.mail.Session instances that may be used for sending electronic mail messages, preconfigured to connect to the appropriate SMTP server.</description>
>     <res-ref-name>mail/Session</res-ref-name>
>     <res-type>javax.mail.Session</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>
>
> My webapp code
>
> Context initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("java:comp/env");
> javax.mail.Session msession = (javax.mail.Session) envCtx.lookup("mail/Session");
> System.out.println("msession to string is " + msession.getProperty("mail.smtp.host"));
>
> For some reasons, this work on my Eclipse/Tomcat set up but when I deploy everything to another server, the getProperty always return localhost as the smtp host. I search for all Tomcat log files but could not find anything.
>

1. Tomcat versions = ?

2. The docs say   "4. Install the JavaMail libraries". Did you do it?
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JavaMail_Sessions

3. Are you sure that you have packed the correct context.xml in your WAR?
How do you deploy your application to other server?

4. If you are able to debug it, a place to place a breakpoint is
org.apache.naming.factory.MailSessionFactory class
https://wiki.apache.org/tomcat/FAQ/Developing#Debugging

Best regards,
Konstantin Kolinko

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