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







Mailrsc

print

Action : tom.mailrsc   (Category : tom, Name : mailrsc, By : kikonf)
Complete Name : tom.mailrsc.by.kikonf
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 http://tomcat.apache.org, jndi-resources-howto.html
This documentation IS NOT the official documentation.
For the offical Tomcat doecumentation please refer to the previous Tomcat official site (http://tomcat.apache.org).


1. TOMCAT JNDI RESOURCES NAMESPACES

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 resources.global : true
or
_ Local using scope context (and/or an affiliated : context.global, default_context.global, default_context)

Note:
-----
When the Global Scope is requested for an Action setting resources.global to "true" into the Action file.
The use of context (and/or an affiliated : context.global, default_context.global, 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.


2. PRERIQUISITES

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.


3. USING JAVA MAIL SESSION WITH TOMCAT

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

<resource-ref>
<res-ref-name>
mail/Session
</res-ref-name>
<res-type>
javax.mail.Session
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>


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.setSubject(request.getParameter("subject"));
message.setContent(request.getParameter("content"), "text/plain");
Transport.send(message);



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