Home > wikikonf >  tom/actions/by kikonf > mailrsc



Action : tom.mailrsc   (Category : tom, Name : mailrsc, By : kikonf)
Complete Name :
Version : 4.0        License : Modified BSD License

Purpose of the tom category :
Easy to customize. This category use in background the Kikonf Repoz tools to create and configure Apache Tomcat root installs and Catalina bases at any level (server.xml, hosts or defaults).
You can use it to manage the whole Tomcat Architecture.

Purpose of this mailrsc plugin : This Action configures a Tomcat Java Mail Resource.

The following shows in what part of a typical Architecture is likely to be found, the Resource configured by Action : tom.mailrsc

This Action configures a Tomcat Java Mail Resource.

This standard resource factory will create javax.mail.Session session instances,
already connected to the SMTP server

Notice :
This documentation contains excerpts from the Tomcat official site, jndi-resources-howto.html
This documentation IS NOT the official documentation.
For the offical Tomcat doecumentation please refer to the previous Tomcat official site (


The following is a general rule for all for all the JNDI Resources configured inside Tomcat >= 5.

JNDI Resources can de declared at the global level or at the context level.

Tomcat 5 maintains a separate namespace of global resources for the entire server. 
These are configured in the <GlobalNamingResources> element of $CATALINA_BASE/conf/server.xml.
You may expose these resources to web applications by using a <ResourceLink> to include it in the per-web-application context.

Converted into the Kikonf scheme the previous stanza means that the scope for a JNDI Resource is either :
_ Global using  scope : true
_ Local using scope context (and/or an affiliated :,, default_context)

When the Global Scope is requested for an Action setting to "true" into the Action file.
The use of context (and/or an affiliated :,, default_context) is allowed.
In this case the resource is declared at the Global level.
But a ResourceLink is also created for the provided context Scope.
This is the reason why, all the Kikonf Actions for Tomcat JNDI Resources alWays support a "link" tag.


Install the JavaMail libraries

Download the JavaMail API.
The JavaMail API requires the Java Activation Framework (JAF) API as well.
The Java Activation Framework can be downloaded from Sun's site.

This download includes 2 vital libraries for the configuration; activation.jar and mail.jar.
Unpackage both distributions and place them into $CATALINA_HOME/common/lib so that they are available
to Tomcat during the initialization of the mail Session Resource.


The following is a short tutorial about how to use a Java Mail Session with Tomcat.

3.1 Add a resource-ref entry into your web application deployment descriptor web.xml


3.2 Run Kikonf Action mailrsc.

3.3 Sample code

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(request.getParameter("from"));
InternetAddress to[] = new InternetAddress[1];
to[0] = new InternetAddress(request.getParameter("to"));
message.setRecipients(Message.RecipientType.TO, to);
message.setContent(request.getParameter("content"), "text/plain");

Trademarks :
  • "Apache", "Apache Tomcat" and "Tomcat" are trademarks of the Apache Software Foundation.
  • "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • Other names may be trademarks of their respective owners.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud