Cocoon でメールを送る

sendmail transformer を使う方法.

1. 依存するパッケージのインストール

JavaMail と JavaBeans Activation Framework (JAF) が必要となります.

JavaMail http://java.sun.com/products/javamail/
JAF http://java.sun.com/products/javabeans/glasgowjaf.html

まずダウンロードしてきて mail.jar と activation.jar を WEB-INF/lib へコピーします.
あと,WEB-INF/lib 以下に geronimo-spec-javamail-1.3.1-rc5.jar と geronimo-spec-activation-1.0.2-rc4.jar
があれば消去します.


2. SendMailTransformer の sitemap.xmap への登録


<map:transformer
name="sendmail"
src="org.apache.cocoon.mail.transformation.SendMailTransformer"/>
を map:transformers 直下へ記述.

3. 例

sitemap.xmap へ

<!-- mail test -->
<map:match pattern="mailme">
<map:generate src="xml/sendmail.xml"/>
<map:transform type="sendmail"/>
<map:serialize type="xml"/>
</map:match>
を記述.もちろん map:pipeline の直下へ.

xml/sendmail.xml はこんな感じ.


<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:email="http://apache.org/cocoon/transformation/sendmail">
<email:sendmail>
<email:smtphost>smtp.server.address</email:smtphost>
<email:smtpport>25</email:smtpport>
<email:from>mail@from.address</email:from>
<email:to>mail@to.address</email:to>
<email:subject>The subject of the mail</email:subject>
<email:body>The body of the mail</email:body>
</email:sendmail>
</document>

smtpport は 465 番 (セキュアな方) にしても送れた.
セキュアになっているかどうかは分からない.