org.apache.cocoon.mail
Class MailMessageSender

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.mail.MailMessageSender
All Implemented Interfaces:
Initializable, Component, Configurable, LogEnabled, Serviceable, MailSender

public class MailMessageSender
extends AbstractLogEnabled
implements MailSender, Configurable, Serviceable, Initializable, Component

A helper class used by the Sendmail and the sendmail.xsl logicsheet for sending an email message.

Configuration

smtp-hostSMTP server to use sending mail.optStringlocalhost
smtp-userUser name for authenticationoptString
smtp-passwordPassword for authenticationoptString

Since:
2.1
Version:
$Id: MailMessageSender.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Frank Ridderbusch, Christian Haul

Field Summary
 
Fields inherited from interface org.apache.cocoon.mail.MailSender
ROLE
 
Constructor Summary
MailMessageSender()
           
MailMessageSender(String smtpHost)
          Deprecated. Since 2.1.5. Please use MailSender component instead.
 
Method Summary
 void addAttachment(Object attachment)
          Add an attachement to the message to be send.
 void addAttachment(Object attachment, String type, String name)
          Add an attachement to the message to be send.
 void addAttachmentURL(String url)
          Add an attachement to the message to be send.
 void addAttachmentURL(String url, String type, String name)
          Add an attachement to the message to be send.
 void configure(Configuration config)
           
 Exception getException()
          Accesses any Exception caught by sendIt(org.apache.cocoon.environment.SourceResolver).
 void initialize()
           
 void send()
          Assemble the message from the defined fields and send it.
 void send(SourceResolver resolver)
          Deprecated. Since 2.1.5. Use send() which doesn't require passing the source resolver
 boolean sendIt()
          Invokes the send() method but catches any exception thrown.
 boolean sendIt(SourceResolver resolver)
          Deprecated. Since 2.1.5. Use sendIt() which doesn't require passing the source resolver
 void service(ServiceManager manager)
           
 void setBcc(String bcc)
          Sets the address(es), which should receive a black carbon copy of the message.
 void setBody(Object body)
          Sets the body content of the email message.
 void setBody(Object body, String type)
          Sets the body content of the email message.
 void setBody(String body)
          Deprecated. Since 2.1.10. Use setBody(Object)
 void setBodyFromSrc(String src)
          Deprecated. Since 2.1.10. Use setBodyURL(String)
 void setBodyFromSrcMimeType(String srcMimeType)
          Deprecated. Since 2.1.10. Use setBodyURL(String, String)
 void setBodyURL(String url)
          Sets the body content of the email message.
 void setBodyURL(String url, String type)
          Sets the body content of the email message.
 void setCc(String cc)
          Sets the address(es), which should receive a carbon copy of the message.
 void setCharset(String charset)
          Sets the character set for encoding the message.
 void setFrom(String from)
          Set the from address of the message.
 void setReplyTo(String replyTo)
          Sets the reply-to address(es) for the message.
 void setSmtpHost(String hostname)
          Set SMTP hostname to use for mail sending.
 void setSmtpHost(String hostname, String username, String password)
          Set SMTP hostname, username, and password to use for mail sending.
 void setSubject(String subject)
          Sets the subject line of the message.
 void setTo(String to)
          Sets the destination address(es) for the message.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailMessageSender

public MailMessageSender()

MailMessageSender

public MailMessageSender(String smtpHost)
Deprecated. Since 2.1.5. Please use MailSender component instead.

Creates a new instance of MailMessageSender. Keep constructor for backwards compatibility.

Parameters:
smtpHost - The host name or ip-address of a host to accept the email for delivery.
Method Detail

service

public void service(ServiceManager manager)
Specified by:
service in interface Serviceable

configure

public void configure(Configuration config)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException

initialize

public void initialize()
Specified by:
initialize in interface Initializable

setSmtpHost

public void setSmtpHost(String hostname)
Description copied from interface: MailSender
Set SMTP hostname to use for mail sending.

Specified by:
setSmtpHost in interface MailSender

setSmtpHost

public void setSmtpHost(String hostname,
                        String username,
                        String password)
Description copied from interface: MailSender
Set SMTP hostname, username, and password to use for mail sending.

Specified by:
setSmtpHost in interface MailSender

send

public void send()
          throws AddressException,
                 MessagingException
Assemble the message from the defined fields and send it.

Specified by:
send in interface MailSender
Throws:
AddressException - when problems with email addresses are found
MessagingException - when message could not be send.

send

public void send(SourceResolver resolver)
          throws AddressException,
                 MessagingException
Deprecated. Since 2.1.5. Use send() which doesn't require passing the source resolver

Assemble the message from the defined fields and send it.

Specified by:
send in interface MailSender
Throws:
AddressException - when problems with email addresses are found
MessagingException - when message could not be send.

sendIt

public boolean sendIt()
Invokes the send() method but catches any exception thrown. This method is intended to be used from the sendmail logicsheet.

Specified by:
sendIt in interface MailSender
Returns:
true when successful

sendIt

public boolean sendIt(SourceResolver resolver)
Deprecated. Since 2.1.5. Use sendIt() which doesn't require passing the source resolver

Invokes the send(org.apache.cocoon.environment.SourceResolver) method but catches any exception thrown. This method is intended to be used from the sendmail logicsheet.

Specified by:
sendIt in interface MailSender
Returns:
true when successful

getException

public Exception getException()
Accesses any Exception caught by sendIt(org.apache.cocoon.environment.SourceResolver).

Specified by:
getException in interface MailSender
Returns:
AddressException or MessagingException

setFrom

public void setFrom(String from)
Set the from address of the message.

Specified by:
setFrom in interface MailSender
Parameters:
from - The address the message appears to be from.

setTo

public void setTo(String to)
Sets the destination address(es) for the message. The address is in the format, that InternetAddress.parse(String) can handle (one or more email addresses separated by a commas).

Specified by:
setTo in interface MailSender
Parameters:
to - the destination address(es)
See Also:
InternetAddress.parse(String)

setReplyTo

public void setReplyTo(String replyTo)
Sets the reply-to address(es) for the message. The address is in the format, that InternetAddress.parse(String) can handle (one or more email addresses separated by a commas).

Specified by:
setReplyTo in interface MailSender
Parameters:
replyTo - the address(es) that replies should be sent to
See Also:
InternetAddress.parse(String)

setCc

public void setCc(String cc)
Sets the address(es), which should receive a carbon copy of the message. The address is in the format, that InternetAddress.parse(String) can handle (one or more email addresses separated by a commas).

Specified by:
setCc in interface MailSender
Parameters:
cc - the address(es), which should receive a carbon copy.
See Also:
InternetAddress.parse(String)

setBcc

public void setBcc(String bcc)
Sets the address(es), which should receive a black carbon copy of the message. The address is in the format, that InternetAddress.parse(String) can handle (one or more email addresses separated by a commas).

Specified by:
setBcc in interface MailSender
Parameters:
bcc - the address(es), which should receive a black carbon copy.
See Also:
InternetAddress.parse(String)

setSubject

public void setSubject(String subject)
Sets the subject line of the message.

Specified by:
setSubject in interface MailSender
Parameters:
subject - the subject line of the message

setCharset

public void setCharset(String charset)
Sets the character set for encoding the message. This has no effect, if any attachments are send in the message.

Specified by:
setCharset in interface MailSender
Parameters:
charset - the character set to be used for enbcoding the message

setBody

public void setBody(String body)
Deprecated. Since 2.1.10. Use setBody(Object)

Sets the body text of the email message. If both a text body and a body read from a source are set, only the latter will be used.

Specified by:
setBody in interface MailSender
Parameters:
body - The body text of the email message

setBodyFromSrc

public void setBodyFromSrc(String src)
Deprecated. Since 2.1.10. Use setBodyURL(String)

Sets the body source URL of the email message. If both a text body and a body read from a source are set, only the latter will be used.

Specified by:
setBodyFromSrc in interface MailSender
Parameters:
src - The body source URL of the email message

setBodyFromSrcMimeType

public void setBodyFromSrcMimeType(String srcMimeType)
Deprecated. Since 2.1.10. Use setBodyURL(String, String)

Sets the optional body source Mime Type of the email message.

Specified by:
setBodyFromSrcMimeType in interface MailSender
Parameters:
srcMimeType - The optional body source Mime Type of the email message

setBody

public void setBody(Object body)
Sets the body content of the email message.

The body can be any of: Source, Part, InputStream, byte[], String, or a subclass.

Specified by:
setBody in interface MailSender
Parameters:
body - The body text of the email message

setBody

public void setBody(Object body,
                    String type)
Sets the body content of the email message.

The body can be any of: Source, Part, InputStream, byte[], String, or a subclass.

Specified by:
setBody in interface MailSender
Parameters:
body - The body text of the email message
type - mime type (optional)

setBodyURL

public void setBodyURL(String url)
Sets the body content of the email message.

Specified by:
setBodyURL in interface MailSender
Parameters:
url - URL to use as message body
See Also:
Source

setBodyURL

public void setBodyURL(String url,
                       String type)
Sets the body content of the email message.

Specified by:
setBodyURL in interface MailSender
Parameters:
url - URL to use as message body
type - mime type (optional)
See Also:
Source

addAttachment

public void addAttachment(Object attachment)
Add an attachement to the message to be send.

The attachment can be any of: Source, Part, InputStream, byte[], String, or a subclass.

Specified by:
addAttachment in interface MailSender
Parameters:
attachment - to be send with the message

addAttachment

public void addAttachment(Object attachment,
                          String type,
                          String name)
Add an attachement to the message to be send.

The attachment can be any of: Source, Part, InputStream, byte[], String, or a subclass.

Specified by:
addAttachment in interface MailSender
Parameters:
attachment - to be send with the message
type - mime type (optional)
name - attachment name (optional)

addAttachmentURL

public void addAttachmentURL(String url)
Add an attachement to the message to be send.

Specified by:
addAttachmentURL in interface MailSender
Parameters:
url - URL to attach to the message
See Also:
Source

addAttachmentURL

public void addAttachmentURL(String url,
                             String type,
                             String name)
Add an attachement to the message to be send.

Specified by:
addAttachmentURL in interface MailSender
Parameters:
url - URL to attach to the message
type - mime type (optional)
name - attachment name (optional)
See Also:
Source


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.