org.apache.cocoon.mail.transformation
Class SendMailTransformer
java.lang.Object
org.apache.cocoon.util.AbstractLogEnabled
org.apache.cocoon.xml.AbstractXMLProducer
org.apache.cocoon.xml.AbstractXMLPipe
org.apache.cocoon.transformation.AbstractTransformer
org.apache.cocoon.transformation.AbstractSAXTransformer
org.apache.cocoon.mail.transformation.SendMailTransformer
- All Implemented Interfaces:
- Configurable, ContentHandler, Disposable, LexicalHandler, Poolable, Recyclable, Serviceable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.transformation.Transformer, XMLConsumer, org.apache.cocoon.xml.XMLConsumer, org.apache.cocoon.xml.XMLPipe, org.apache.cocoon.xml.XMLProducer
- public class SendMailTransformer
- extends org.apache.cocoon.transformation.AbstractSAXTransformer
The SendMailTransformer
send mails with optional attachments using a SMTP
server and delivers furthermore a status report of each sent mail.
The SendMailTransformer requires the Sun's JavaMail API implementation. Please
download and copy the following files to the Cocoon lib directory:
<map:transformer name="sendmail" src="org.apache.cocoon.mail.transformation.SendMailTransformer">
<smtphost>smtp.foo.com</smtphost>
<from>sender@localhost</from>
</map:transformer>
where
-
<smtphost> is the SMTP server host name, e.g. smtp.foo.com
-
<from> is the sender e-mail address
Furthermore, these parameters can be defined in the sitemap pipeline section:
-
smtphost, from - If they are defined, this values overwrite
the values from component section described above.
-
to - email addresses of recipients
e.g.:
<map:parameter name="to" value="customer1@target.com,customer2@target.com"/>
-
subject - a string, can also come from an input module
e.g.; <map:parameter name="subject" value="{request-param:subject}"/>
-
body - a string, can also come from an input module
e.g.; <map:parameter name="body" value="{request-param:body}"/>
-
sendpartial - a boolean, define how to send the mails. When mail is being send
to more than one recipient and the parameter is set to false, then all email addresses
will appear concatenated in the address field at the mail client of the recipient.
The default is true.
More configurations can be made in a specific configuration file, which
can be retrieved with a
generator as
the input document. The input document should have the following configuration entities:
-
<email:smtphost>, <email:from> and
<email:subject> can be set to overwrite values from the
sitemap
-
<email:to> - each entry will be append to the list of
email addresses
-
<email:body> - Overwrites the value from the sitemap.
If there is a src attribute, the transformer will try to retrieve
the file and place it instead of a text-string as the mail body.
-
<email:attachment> - each entry defines a attachment.
The attribute name defines the name of the attachment. The mime-type attribute
defines the content of the attachment.
If there is a nested <email:content> - element, text can be included and the
attachment will then be a plain text-file.
Is there a url attribute, the transformer tries to retrieve the
appropriate file and handle it as an attachment.
To use a file as an attachment, retrieved over a protocol like http or
cocoon, use the src attribute.
Input document sample:
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:email="http://apache.org/cocoon/transformation/sendmail">
<email:sendmail>
<email:smtphost>hostname.company.com</email:smtphost>
<email:from>info@company.com</email:from>
<email:to>customer3@target.com</email:to>
<email:to>customer4@target.com</email:to>
<email:to>customer5@target.com</email:to>
<email:to>customer6@target.com</email:to>
<email:subject>subject-content</email:subject>
<email:body src="cocoon:/softwareupdate.html?locale=en&country=UK"/>
<!-- <email:body>some Text</email:body> -->
<email:attachment name="hello.html" mime-type="text/html">
<email:content>
Dear Customer, please visit out new Product-Shop.
</email:content>
</email:attachment>
<email:attachment name="hello2.html" mime-type="text/html" src="cocoon:/src1"/>
<email:attachment name="hello3.html" mime-type="text/html"
url="C:\path\softwareupdate.html"/>
<email:attachment name="hello.gif" mime-type="image/gif"
url="c:\path\powered.gif"/>
</email:sendmail>
</document>
After the transformation a report will be generated, where the state for each sent mail can be seen.
In case of an exception, the exception-message and a stacktrace will be reported.
FIXME: Known Issues:
- Version:
- $Id: SendMailTransformer.html 1304280 2012-03-23 11:18:01Z ilgrosso $
Fields inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer |
context, defaultNamespaceURI, EMPTY_ATTRIBUTES, ignoreEmptyCharacters, ignoreEventsCount, ignoreHooksCount, ignoreWhitespaces, manager, namespaceURI, objectModel, parameters, recorderStack, removeOurNamespacePrefixes, request, resolver, response, source, stack |
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer |
Fields inherited from interface org.apache.cocoon.transformation.Transformer |
ROLE |
Methods inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer |
addRecorder, characters, comment, dispose, endCDATA, endDocument, endDTD, endElement, endEntity, endParametersRecording, endParametersRecording, endPrefixMapping, endRecording, endSAXRecording, endSerializedXMLRecording, endTextRecording, findPrefixMapping, getMutableAttributes, ignorableWhitespace, processingInstruction, removeRecorder, sendEndElementEvent, sendEndElementEventNS, sendEndPrefixMapping, sendEvents, sendParametersEvents, sendStartElementEvent, sendStartElementEvent, sendStartElementEventNS, sendStartElementEventNS, sendStartPrefixMapping, sendTextEvent, service, setDocumentLocator, setupTransforming, skippedEntity, startCDATA, startDocument, startDTD, startElement, startEntity, startParametersRecording, startPrefixMapping, startRecording, startSAXRecording, startSerializedXMLRecording, startTextRecording |
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
setConsumer, setContentHandler, setLexicalHandler |
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled |
getLogger, setLogger |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.cocoon.xml.XMLProducer |
setConsumer |
NAMESPACE
public static final String NAMESPACE
- See Also:
- Constant Field Values
ELEMENT_SENDMAIL
public static final String ELEMENT_SENDMAIL
- See Also:
- Constant Field Values
ELEMENT_SMTPHOST
public static final String ELEMENT_SMTPHOST
- See Also:
- Constant Field Values
ELEMENT_SMTPPORT
public static final String ELEMENT_SMTPPORT
- See Also:
- Constant Field Values
ELEMENT_MAILFROM
public static final String ELEMENT_MAILFROM
- See Also:
- Constant Field Values
ELEMENT_MAILTO
public static final String ELEMENT_MAILTO
- See Also:
- Constant Field Values
ELEMENT_REPLYTO
public static final String ELEMENT_REPLYTO
- See Also:
- Constant Field Values
ELEMENT_MAILSUBJECT
public static final String ELEMENT_MAILSUBJECT
- See Also:
- Constant Field Values
ELEMENT_MAILBODY
public static final String ELEMENT_MAILBODY
- See Also:
- Constant Field Values
ELEMENT_ATTACHMENT
public static final String ELEMENT_ATTACHMENT
- See Also:
- Constant Field Values
ELEMENT_ATTACHMENT_CONTENT
public static final String ELEMENT_ATTACHMENT_CONTENT
- See Also:
- Constant Field Values
ELEMENT_EMAIL_PREFIX
public static final String ELEMENT_EMAIL_PREFIX
- See Also:
- Constant Field Values
ELEMENT_ERROR
public static final String ELEMENT_ERROR
- See Also:
- Constant Field Values
ELEMENT_SUCCESS
public static final String ELEMENT_SUCCESS
- See Also:
- Constant Field Values
ELEMENT_FAILURE
public static final String ELEMENT_FAILURE
- See Also:
- Constant Field Values
ELEMENT_RESULT
public static final String ELEMENT_RESULT
- See Also:
- Constant Field Values
DEFAULT_BODY_MIMETYPE
public static final String DEFAULT_BODY_MIMETYPE
- See Also:
- Constant Field Values
MODE_NONE
protected static final int MODE_NONE
- See Also:
- Constant Field Values
MODE_SMTPHOST
protected static final int MODE_SMTPHOST
- See Also:
- Constant Field Values
MODE_FROM
protected static final int MODE_FROM
- See Also:
- Constant Field Values
MODE_TO
protected static final int MODE_TO
- See Also:
- Constant Field Values
MODE_SUBJECT
protected static final int MODE_SUBJECT
- See Also:
- Constant Field Values
MODE_BODY
protected static final int MODE_BODY
- See Also:
- Constant Field Values
MODE_ATTACHMENT
protected static final int MODE_ATTACHMENT
- See Also:
- Constant Field Values
MODE_ATTACHMENT_CONTENT
protected static final int MODE_ATTACHMENT_CONTENT
- See Also:
- Constant Field Values
MODE_REPLY_TO
protected static final int MODE_REPLY_TO
- See Also:
- Constant Field Values
MODE_SMTPPORT
protected static final int MODE_SMTPPORT
- See Also:
- Constant Field Values
PARAM_SMTPHOST
public static final String PARAM_SMTPHOST
- See Also:
- Constant Field Values
PARAM_SMTPPORT
public static final String PARAM_SMTPPORT
- See Also:
- Constant Field Values
PARAM_FROM
public static final String PARAM_FROM
- See Also:
- Constant Field Values
PARAM_TO
public static final String PARAM_TO
- See Also:
- Constant Field Values
PARAM_REPLY_TO
public static final String PARAM_REPLY_TO
- See Also:
- Constant Field Values
PARAM_SUBJECT
public static final String PARAM_SUBJECT
- See Also:
- Constant Field Values
PARAM_BODY
public static final String PARAM_BODY
- See Also:
- Constant Field Values
PARAM_SENDPARTIAL
public static final String PARAM_SENDPARTIAL
- See Also:
- Constant Field Values
mode
protected int mode
toAddresses
protected List toAddresses
replyToAddresses
protected List replyToAddresses
defaultToAddresses
protected List defaultToAddresses
defaultReplyToAddresses
protected List defaultReplyToAddresses
attachments
protected List attachments
subject
protected String subject
body
protected String body
bodyURI
protected String bodyURI
bodyMimeType
protected String bodyMimeType
mailHost
protected String mailHost
mailPort
protected int mailPort
fromAddress
protected String fromAddress
attachmentDescriptor
protected org.apache.cocoon.mail.transformation.SendMailTransformer.AttachmentDescriptor attachmentDescriptor
port
protected int port
contextPath
protected String contextPath
sendPartial
protected boolean sendPartial
smtpMessage
protected Message smtpMessage
defaultSmtpHost
protected String defaultSmtpHost
defaultSmtpPort
protected int defaultSmtpPort
defaultFromAddress
protected String defaultFromAddress
usedSources
protected List usedSources
SendMailTransformer
public SendMailTransformer()
- create a new Transformer
configure
public void configure(Configuration configuration)
throws ConfigurationException
- Throws:
ConfigurationException
setup
public void setup(org.apache.cocoon.environment.SourceResolver resolver,
Map objectModel,
String src,
Parameters par)
throws org.apache.cocoon.ProcessingException,
SAXException,
IOException
- invoked every time when the transformer is triggered by the pipeline
- Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException
startTransformingElement
public void startTransformingElement(String uri,
String name,
String raw,
Attributes attr)
throws SAXException
- Throws:
SAXException
endTransformingElement
public void endTransformingElement(String uri,
String name,
String raw)
throws SAXException,
org.apache.cocoon.ProcessingException
- Throws:
SAXException
org.apache.cocoon.ProcessingException
getAddresses
public static InternetAddress[] getAddresses(org.apache.cocoon.mail.transformation.SendMailTransformer.AddressHandler[] handlerArr)
recycle
public void recycle()
- See Also:
Recyclable.recycle()
Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.