Apache » Cocoon »

  Cocoon Mail

Cocoon Mail 1.0



The SendMailTransformer send mails with optional attachments using a SMTP server and delivers furthermore a status report of each sent mail.

Basic information

Component typeTransformer
Cocoon blockmail
Java classorg.apache.cocoon.mail.transformation.SendMailTransformer
Name in Sitemap


Using SendMailTransfomer with Cocoon 2.1.8 or recent

Note: The SendMailTransformer needs the JavaMail and JavaBeans Activation Framework (JAF) API's from Sun to work. Add them to WEB-INF/lib. Remove geronimo-spec-javamail-*.jar and geronimo-spec-activation-*.jar from WEB-INF/lib. For more information, see Problem & Solution.

Simple example

Add this to the transformers in your sitemap

<map:transformer name="sendmail" src="org.apache.cocoon.mail.transformation.SendMailTransformer"/>

Add this in a pipeline in your sitemap

<map:match pattern="mailme">
    <map:generate src="sendmail.xml"/>
    <map:transform type="sendmail"/>
    <map:serialize type="xml"/>

Example of sendmail.xml. The values in this document override those from the sitemap. You can remove them here if you have set them in the sitemap.

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:email="http://apache.org/cocoon/transformation/sendmail">
        <email:subject>My first mail</email:subject>
        <email:body>The body of the mail</email:body>

Advanced examples and parameters

See the  APIdoc

Problem & Solution


It doesn't matter which SMTP-Host (or SMTP-Port) you fill in, you get the following error:

"Could not connect to SMTP host: localhost, port: 25 (java.net.ConnectException: Connection refused: connect)"

if you have a mailserver running on your machine on port 25:

Exception sending mail java.lang.ClassCastException: java.lang.String


Cocoon uses geronimo-spec-javamail-*.jar and geronimo-spec-activation-*.jar instead of Sun JavaMail and JAF.

Due to licensing issues, it is not possible to ship the Sun jars with Cocoon, but without these jars, Cocoon would not compile. Therefore the geronimo jars are included.

Remove geronimo-spec-javamail-*.jar and geronimo-spec-activation-*.jar from WEB-INF/lib and restart Cocoon.

If this still doesn't work remove geronimo-spec-javamail-*.jar from /lib/optional and remove it in lib/jars.xml (or comment it with <!-- -->). Copy src/blocks/mail/mocks from Cocoon 2.1.7 to the same directory in Cocoon 2.1.8 and rebuild Cocoon. Then add Sun JavaMail and Activation into WEB-INF/lib and remove geronimo-spec-activation-*.jar.

Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).