apache > lenya
 

The MailTask

A MailTask sends an e-mail. The parameters, such as recipient address, subject, and body, can either be provided as a task parameter or extracted from an XML document.

Task Parameters

The following parameters must be provided:

  • server: the SMTP server URI
  • from: you@yourhost.com
  • to: friend@mail.com
  • cc: other-friends@mail.com
  • subject: Hello World!
  • body: How are you?

Getting the mail data from an XML source

Additionally, you can pass a uri parameter to the MailTask:

  • uri: the URI to get the XML file from

If this parameter is present, the task tries to fetch an XML document from the URI. If the parameter uri starts with a http:// or ftp:// prefix, the absolute URI is used. If not, the URI is interpreted as relative to the local publication.

A complete XML document could look like this:


<mail:mail xmlns:mail="http://apache.org/cocoon/lenya/mail/1.0">
  <mail:server>mail.yourhost.com</mail:server>
  <mail:from>you@yourhost.com</mail:from>
  <mail:to>friend@mail.com</mail:to>
  <mail:cc>other-friends@mail.com</mail:cc>
  <mail:subject>Hello Friends!</mail:subject>
  <mail:body>How are you?</mail:body>
</mail:mail>

All child elements of <mail:mail> are optional. If the uri task parameter is provided, the XML document is fetched from the URI and the parameters are extracted.

Task parameters have a higher priority than elements of the document. This makes it possible to access one complete XML file from different MailTasks and override the recepient address or other values.

Declaring and Using the MailTask

In tasks.xconf, a typical mail task looks like follows:


  <task id="send-newsletter" class="org.lenya.cms.mail.MailTask">
    <label>Send Newsletter</label>
    <parameter name="server" value="mail.example.com"/>
    <parameter name="from" value="info@example.com"/>
    <parameter name="to" value="newsletter-subscribers@example.com"/>
    <parameter name="uri" value="/authoring/newsletter/mail.xml"/>
  </task>

The actual newsletter is received from the URI that is interpreted relativly to the publication URI. The task can be invoked in a sitemap pipeline:


  <map:action name="task" src="org.lenya.cms.cocoon.acting.TaskAction"/>
  
  ...
  
  <map:match pattern="newsletter/send">
    <map:act type="task">
      <map:parameter name="task-id" value="send-newsletter"/>
      <map:redirect-to uri="report-success.html" session="true"/>
    </map:act>
    <map:redirect-to uri="report-failure.html" session="true"/>
  </map:match>