The most common use of a JNDI resource in JRuby-land is for configuring datasources. But now I wanted to have ActionMailer send emails using a JNDI config. So how to do it?
Do not fear! JRuby is your friend and every old java trick can be used.
So let's create the JNDI resource which is an javax.mail.Session pointing to localhost. This is what one would normally find in Tomcat's context.xml file (pastie):
Then let's create an adapter to do look ups for us (pastie):
And finally a simple test to see if it works (pastie):
Pretty easy huh?