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="http://apache.org/cocoon/transformation/sendmail">
<email:sendmail>
<!--
SMTP host configuration, can also be defined when
declaring the SendmailTransformer component.
-->
<email:smtphost>your.smtp.server</email:smtphost>
<email:from>cocoon@codeconsult.ch</email:from>

<!-- The rest is self-explaining -->
<email:to>bdelacretaz@codeconsult.ch</email:to>
<email:to>someone-else@codeconsult.ch</email:to>

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

<email:body>
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.
</email:body>

<-- use pipelines for attachments to show how this works -->
<email:attachment
name="logo"
mime-type="image/gif"
src="cocoon:/read-file/iconPDF.gif"
/>

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

<email:attachment
name="report file"
mime-type="application/pdf"
src="cocoon:/read-file/pdf-document.pdf"
/>

</email:sendmail>
</document>

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).

    Regards.

  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(MimeMessage.java:274)
    at javax.mail.Message.addRecipient(Message.java:230)
    at org.apache.cocoon.peruthisweek.action.MailAction.buildMessage(MailAction.java:44)
    at org.apache.cocoon.peruthisweek.action.MailAction.sendMail(MailAction.java:21)
    at org.apache.cocoon.peruthisweek.action.CommentAction.Send_Email(CommentAction.java:78)
    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 “Message.java:230” returns quite a few pages, the thread at http://markmail.org/message/72oniopmtiq66l54 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: