Mail from Cocoon is fun and easy

Believe it or not, today is the first time that I used the Cocoon mail block, to create an example for a customer.

What I found is that it’s dead easy to use: activate the mail block, download two jars which cannot be distributed with Cocoon (mail.jar and activation.jar), feed a document like the example below to the SendmailTransformer and you’re done. Of course, all the components of the transformer’s input document (including binary attachments) can be generated dynamically using Cocoon pipelines.

The transformer output indicates whether the message was successfully sent to each address, it’s really simple and very useful. You should be prepared to receive spam lots of interesting messages from my next Cocoon application ;-)

<?xml version="1.0">

Test input for the Cocoon sendmail transformer.

To send an email, activate the Cocoon mail block
(requires mail.jar and activation.jar which are not
distributed with Cocoon), and feed this to the
SendmailTransformer. That's it.

Of course, this document and all its content could
be generated from various pipelines, the cocoon:/
protocol is fully supported.

<document xmlns:email="">
SMTP host configuration, can also be defined when
declaring the SendmailTransformer component.

<!-- The rest is self-explaining -->

<email:subject>This is a test, from sendmail-input.xml</email:subject>

This is the body of the test message.
By using src="cocoon:/somepipeline" in the email:body
element, this
could be generated dynamically from a Cocoon pipeline.
The message contains three attachments: a small PDF logo,
and HTML document with a single line in it, and a PDF document.

<-- use pipelines for attachments to show how this works -->

<email:attachment name="stuff-in-html.html" mime-type="text/html">
<email:content>This is supposed to be an HTML attachment.</email:content>

name="report file"


10 Responses to Mail from Cocoon is fun and easy

  1. Éric BURGHARD says:

    I’m just quite like you (interrested by the MailTransformer after 2 years of cocoon-dev).

    I’ve just submit a patch in cocoon-dev for handling alternatives bodies in an email (not an option for corporate emails).


  2. Matt says:

    How do you “activate” the mail block?

  3. bdelacretaz says:

    To activate the block in Cocoon 2.1.x, follow the instructions in the INSTALL.txt file.

  4. Zuro says:

    good afternoon i have a problem with the jars i think that coccon is not recognize them…. i already reference them and put it into web-inf/lib …. but i get the fallow error

    java.lang.UnsupportedOperationException: Method not yet implemented
    at javax.mail.internet.MimeMessage.addRecipients(
    at javax.mail.Message.addRecipient(
    at org.apache.cocoon.peruthisweek.action.MailAction.buildMessage(
    at org.apache.cocoon.peruthisweek.action.MailAction.sendMail(
    at org.apache.cocoon.peruthisweek.action.CommentAction.Send_Email(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

  5. @Zuro, as the stack trace indicates, the javax.mail classes have been found. Searching the web for “Method not yet implemented” and “” returns quite a few pages, the thread at will probably help.

    Also ,the org.apache.cocoon.peruthisweek… package seems to indicate that you’re not running original Cocoon code.

  6. Zuro says:

    Thank you very much. Actually, I had to delete the geronimos jars, and I put instead the mail.jar and the activation.jar and now it´s working.

    Thank you for your help, Bertrand Delacretaz

  7. Zuro says:

    I have a question about the Xplanner.

    I have successfully installed it on my PC. But, when I click on the project name to see its details in the page :8080/xplanner/do/view/projects

    But I get the following error message:

    [ServletException in:/WEB-INF/jsp/layout/viewLayout.jsp] Attempted a bean operation on a null object.’

    I´ve seen that a few people have the same problem. Why do you think is happening that?

    thank you

  8. Jharek says:

    You have to delete the 2 jar files that are in cocoon geronimmail and geronimactivation, i dont remenber the exact name, becouse the cocoon is reading them and not them, after that place the mail.jar and activation.jar

    any questions write me.

  9. c.d says:

    where can i get the last news and get the last release of cocoon mail block ?
    i want to find more info if it can work with xml and rss readers.

    thank you

  10. Thanks for the insight. I’m using flowscripts to implement all of my logic, so it would be nice to send mails from them too. Is there a way to kick off the sending from the flowscripts?

%d bloggers like this: