org.norther.tammi.core.mail
Class DefaultMailer

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.config.DefaultConfigurable
          extended by org.norther.tammi.core.mail.DefaultMailer
All Implemented Interfaces:
Serializable, Runnable, EventListener, NotificationBroadcaster, NotificationEmitter, TraceListener, Manageable, MBeanDelegate, Startable, Configurable, Mailer, Executable

public class DefaultMailer
extends DefaultConfigurable
implements Mailer

The default implementation of Mailer. TODO: Test authentication TODO: Handle other content types and multipart messages TODO: Use event listeners to report unsent messages TODO: Support different providers by getting the transport object from the session

Version:
$Id: DefaultMailer.java,v 1.10 2009/09/28 15:08:45 cvsimp Exp $
Author:
Marketta Priha
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.norther.tammi.core.config.DefaultConfigurable
DefaultConfigurable.Modified
 
Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.mail.Mailer
MAIL_DEBUG_PROPERTY, MAIL_FROM_PROPERTY, MAIL_HOST_PROPERTY, MAIL_MIME_ADDRESS_STRICT_PROPERTY, MAIL_MIME_CHARSET_PROPERTY, MAIL_PORT_PROPERTY, MAIL_PROPERTY_PREFIX, MAIL_TRANSPORT_PROTOCOL_PROPERTY, MAIL_USER_PROPERTY, MAILER_PASSWORD_PROPERTY, MAILER_PROPERTY_PREFIX, MAILER_X_MAILER_PROPERTY
 
Constructor Summary
DefaultMailer()
          Constructs a new mail sender.
 
Method Summary
 void applyServerURL(String server)
          Applies the specified URL to the mail server configuration.
 boolean getDebug()
          Gets debugging flag for JavaMail Session object.
 ObjectName getExecutorName()
          Gets the the executor of this executable.
 javax.mail.internet.InternetAddress getFrom()
          Gets the address of the current user.
 String getHost()
          Gets the host name of the mail server.
 int getPort()
          Gets the port number of the mail server.
 String getProtocol()
          Gets the protocol for sending.
 String getServerURL()
          Gets the mail server to be connected as an URL.
 String getUser()
          Gets the username for connecting the mail server.
 boolean isStarted()
          Checks whether the startable has been started.
 void run()
          Runs in the background message thread that does actual send mail operation using JavaMail.
 void sendMail(javax.mail.internet.InternetAddress[] toAddress, String subject, String messageBody)
          Sends a text-only mail message with minimal addressing information to specified addresses.
 void sendMail(javax.mail.internet.InternetAddress fromAddress, javax.mail.internet.InternetAddress[] replyToAddress, javax.mail.internet.InternetAddress senderAddress, javax.mail.internet.InternetAddress[] toAddress, javax.mail.internet.InternetAddress[] ccAddress, javax.mail.internet.InternetAddress[] bccAddress, String subject, String messageBody)
          Sends a text-only mail message with full addressing information.
 void sendMail(javax.mail.internet.InternetAddress fromAddress, javax.mail.internet.InternetAddress[] replyToAddress, javax.mail.internet.InternetAddress senderAddress, javax.mail.internet.InternetAddress[] toAddress, javax.mail.internet.InternetAddress[] ccAddress, javax.mail.internet.InternetAddress[] bccAddress, String subject, String messageBody, String encoding)
          Sends an encoded text-only mail message with full addressing information.
 void sendMail(javax.mail.internet.InternetAddress fromAddress, javax.mail.internet.InternetAddress[] toAddress, String subject, String messageBody)
          Sends a text-only mail message with less addressing information to specified addresses.
 void sendMail(javax.mail.internet.InternetAddress fromAddress, javax.mail.internet.InternetAddress[] toAddress, String subject, String messageBody, String encoding)
          Sends an encoded text-only mail message with less addressing information to specified addresses.
 void sendMail(javax.mail.internet.InternetAddress fromAddress, javax.mail.internet.InternetAddress toAddress, String subject, String messageBody)
          Sends a text-only mail message with less addressing information to the specified addresses.
 void sendMail(javax.mail.internet.InternetAddress fromAddress, javax.mail.internet.InternetAddress toAddress, String subject, String messageBody, String encoding)
          Sends an encoded text-only mail message with less addressing information to the specified address.
 void sendMail(javax.mail.internet.InternetAddress toAddress, String subject, String messageBody)
          Sends a text-only mail message with minimal addressing information to the specified address.
 void setDebug(boolean debug)
          Sets debugging flag for JavaMail Session object.
 void setExecutorName(ObjectName executor)
          Sets the executor of this executable.
 void setFrom(javax.mail.internet.InternetAddress from)
          Sets the address of the current user.
 void setHost(String host)
          Sets the host name of the mail server.
 void setHost(String host, String protocol)
          Sets the protocol specific host name of the mail server.
 void setPassword(String password)
          Sets the password for connecting the mail server.
 void setPassword(String password, String protocol)
          Sets the protocol specific password for connecting the mail server.
 void setPort(int port)
          Sets the port number of the mail server.
 void setPort(int port, String protocol)
          Sets the protocol specific port number of the mail server.
 void setProtocol(String protocol)
          Sets the protocol for sending.
 void setUser(String user)
          Sets the username for connecting the mail server.
 void setUser(String user, String protocol)
          Sets the protocol specific username for connecting the mail server.
 void start()
          Starts the MBean.
 void stop()
          Stops the mail queue and discards unsent mail messages.
protected  void validateConfiguration(Configuration config)
          Validates the configuration.
 
Methods inherited from class org.norther.tammi.core.config.DefaultConfigurable
addProperty, addProperty, addPropertyFilePath, addPropertyFilePath, checkConfiguration, clearProperties, containsProperty, getConfigKey, getConfiguration, getModifiedState, getProperties, getProperty, getPropertyFilePath, getPropertyFilePaths, indexOfProperty, loadConfiguration, loadConfiguration, loadConfiguration, modified, propertyMap, propertyMap, removeProperty, removeProperty, removePropertyFilePath, setConfigKey, setModifiedState, setProperties, setProperty, setPropertyFilePath, setPropertyFilePath, setPropertyFilePaths, setPropertyFilePaths, storeProperties
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.config.Configurable
addProperty, addProperty, addPropertyFilePath, addPropertyFilePath, clearProperties, containsProperty, getConfigKey, getProperties, getProperty, getPropertyFilePath, getPropertyFilePaths, indexOfProperty, propertyMap, propertyMap, removeProperty, removeProperty, removePropertyFilePath, setConfigKey, setProperties, setProperty, setPropertyFilePath, setPropertyFilePath, setPropertyFilePaths, setPropertyFilePaths, storeProperties
 

Constructor Detail

DefaultMailer

public DefaultMailer()
Constructs a new mail sender.

Method Detail

getExecutorName

public ObjectName getExecutorName()
Description copied from interface: Executable
Gets the the executor of this executable.

Specified by:
getExecutorName in interface Executable
Returns:
the object name of the executor or a query.

setExecutorName

public void setExecutorName(ObjectName executor)
Description copied from interface: Executable
Sets the executor of this executable. If it is not set, the default one will be used.

Note that it will be taken into use after next start.

Specified by:
setExecutorName in interface Executable
Parameters:
executor - the object name of the executor or a query.

isStarted

public boolean isStarted()
Description copied from interface: Startable
Checks whether the startable has been started.

Specified by:
isStarted in interface Startable
Returns:
true if started, otherwise false.

start

public void start()
           throws Exception
Description copied from interface: Startable
Starts the MBean.

Specified by:
start in interface Startable
Throws:
Exception - if start fails.

stop

public void stop()
Stops the mail queue and discards unsent mail messages.

Specified by:
stop in interface Startable

getServerURL

public String getServerURL()
Description copied from interface: Mailer
Gets the mail server to be connected as an URL. A possible password information is hidden.

Specified by:
getServerURL in interface Mailer
Returns:
the URL of the mail server to be connected as a string.

applyServerURL

public void applyServerURL(String server)
Description copied from interface: Mailer
Applies the specified URL to the mail server configuration.

If null is given, initializes both the protocol specific and general settings.

Specified by:
applyServerURL in interface Mailer
Parameters:
server - the URL of the mail server to be connected as a string.

getProtocol

public String getProtocol()
Description copied from interface: Mailer
Gets the protocol for sending.

Specified by:
getProtocol in interface Mailer
Returns:
the protocol e.g. 'SMTP'.

setProtocol

public void setProtocol(String protocol)
Description copied from interface: Mailer
Sets the protocol for sending.

Specified by:
setProtocol in interface Mailer
Parameters:
protocol - the protocol e.g. 'SMTP'.

getHost

public String getHost()
Description copied from interface: Mailer
Gets the host name of the mail server.

Specified by:
getHost in interface Mailer
Returns:
the host name.

setHost

public void setHost(String host)
Description copied from interface: Mailer
Sets the host name of the mail server.

Specified by:
setHost in interface Mailer
Parameters:
host - the host name.

setHost

public void setHost(String host,
                    String protocol)
Description copied from interface: Mailer
Sets the protocol specific host name of the mail server.

Specified by:
setHost in interface Mailer
Parameters:
host - the host name.
protocol - the protocol.

getPort

public int getPort()
Description copied from interface: Mailer
Gets the port number of the mail server.

Specified by:
getPort in interface Mailer
Returns:
the port number.

setPort

public void setPort(int port)
Description copied from interface: Mailer
Sets the port number of the mail server.

Specified by:
setPort in interface Mailer
Parameters:
port - the port number.

setPort

public void setPort(int port,
                    String protocol)
Description copied from interface: Mailer
Sets the protocol specific port number of the mail server.

Specified by:
setPort in interface Mailer
Parameters:
port - the port number.
protocol - the protocol.

getUser

public String getUser()
Description copied from interface: Mailer
Gets the username for connecting the mail server.

Specified by:
getUser in interface Mailer
Returns:
the username.

setUser

public void setUser(String user)
Description copied from interface: Mailer
Sets the username for connecting the mail server.

Specified by:
setUser in interface Mailer
Parameters:
user - the username.

setUser

public void setUser(String user,
                    String protocol)
Description copied from interface: Mailer
Sets the protocol specific username for connecting the mail server.

Specified by:
setUser in interface Mailer
Parameters:
user - the username.
protocol - the protocol.

setPassword

public void setPassword(String password)
Description copied from interface: Mailer
Sets the password for connecting the mail server.

Specified by:
setPassword in interface Mailer
Parameters:
password - the password.

setPassword

public void setPassword(String password,
                        String protocol)
Description copied from interface: Mailer
Sets the protocol specific password for connecting the mail server.

Specified by:
setPassword in interface Mailer
Parameters:
password - the password.
protocol - the protocol.

getFrom

public javax.mail.internet.InternetAddress getFrom()
Description copied from interface: Mailer
Gets the address of the current user. Used by the InternetAddress.getLocalAddress method to specify the current user's email, default username@host.

Specified by:
getFrom in interface Mailer
Returns:
the user mail address.

setFrom

public void setFrom(javax.mail.internet.InternetAddress from)
Description copied from interface: Mailer
Sets the address of the current user. Used by the InternetAddress.getLocalAddress method to specify the current user's email, default username@host.

Specified by:
setFrom in interface Mailer
Parameters:
from - the user mail address.

getDebug

public boolean getDebug()
Description copied from interface: Mailer
Gets debugging flag for JavaMail Session object.

Specified by:
getDebug in interface Mailer
Returns:
the debug flag.

setDebug

public void setDebug(boolean debug)
Description copied from interface: Mailer
Sets debugging flag for JavaMail Session object.

Specified by:
setDebug in interface Mailer
Parameters:
debug - the debug flag.

sendMail

public void sendMail(javax.mail.internet.InternetAddress toAddress,
                     String subject,
                     String messageBody)
              throws LogException
Description copied from interface: Mailer
Sends a text-only mail message with minimal addressing information to the specified address. The 'mail.from' property must have been set.

Specified by:
sendMail in interface Mailer
Parameters:
toAddress - the receiver's mail address.
subject - the subject of the mail.
messageBody - the mail body as text.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress[] toAddress,
                     String subject,
                     String messageBody)
              throws LogException
Description copied from interface: Mailer
Sends a text-only mail message with minimal addressing information to specified addresses. The 'mail.from' property must have been set.

Specified by:
sendMail in interface Mailer
Parameters:
toAddress - the receivers' mail addresses.
subject - the subject of the mail.
messageBody - the mail body as text.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress fromAddress,
                     javax.mail.internet.InternetAddress toAddress,
                     String subject,
                     String messageBody)
              throws LogException
Description copied from interface: Mailer
Sends a text-only mail message with less addressing information to the specified addresses.

Specified by:
sendMail in interface Mailer
Parameters:
fromAddress - the sender's mail address.
toAddress - the receiver's mail address.
subject - the subject of the mail.
messageBody - the mail body as text.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress fromAddress,
                     javax.mail.internet.InternetAddress[] toAddress,
                     String subject,
                     String messageBody)
              throws LogException
Description copied from interface: Mailer
Sends a text-only mail message with less addressing information to specified addresses.

Specified by:
sendMail in interface Mailer
Parameters:
fromAddress - the sender's mail address.
toAddress - the receivers' mail addresses.
subject - the subject of the mail.
messageBody - the mail body as text.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress fromAddress,
                     javax.mail.internet.InternetAddress toAddress,
                     String subject,
                     String messageBody,
                     String encoding)
              throws LogException
Description copied from interface: Mailer
Sends an encoded text-only mail message with less addressing information to the specified address.

Specified by:
sendMail in interface Mailer
Parameters:
fromAddress - the sender's mail address.
toAddress - the receiver's mail address.
subject - the subject of the mail.
messageBody - the mail body as text.
encoding - the charset to be applied.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress fromAddress,
                     javax.mail.internet.InternetAddress[] toAddress,
                     String subject,
                     String messageBody,
                     String encoding)
              throws LogException
Description copied from interface: Mailer
Sends an encoded text-only mail message with less addressing information to specified addresses.

Specified by:
sendMail in interface Mailer
Parameters:
fromAddress - the sender's mail address.
toAddress - the receivers' mail addresses.
subject - the subject of the mail.
messageBody - the mail body as text.
encoding - the charset to be applied.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress fromAddress,
                     javax.mail.internet.InternetAddress[] replyToAddress,
                     javax.mail.internet.InternetAddress senderAddress,
                     javax.mail.internet.InternetAddress[] toAddress,
                     javax.mail.internet.InternetAddress[] ccAddress,
                     javax.mail.internet.InternetAddress[] bccAddress,
                     String subject,
                     String messageBody)
              throws LogException
Description copied from interface: Mailer
Sends a text-only mail message with full addressing information.

Specified by:
sendMail in interface Mailer
Parameters:
fromAddress - the sender's mail address.
replyToAddress - reply to addresses (see RFC822 for details).
senderAddress - sender addresses (see RFC822 for details).
toAddress - the receivers' mail addresses.
ccAddress - the addresses to receive carbon copy of this message.
bccAddress - the addresses to receive blind carbon copy of this message.
subject - the subject of the mail.
messageBody - the mail body as text.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

sendMail

public void sendMail(javax.mail.internet.InternetAddress fromAddress,
                     javax.mail.internet.InternetAddress[] replyToAddress,
                     javax.mail.internet.InternetAddress senderAddress,
                     javax.mail.internet.InternetAddress[] toAddress,
                     javax.mail.internet.InternetAddress[] ccAddress,
                     javax.mail.internet.InternetAddress[] bccAddress,
                     String subject,
                     String messageBody,
                     String encoding)
              throws LogException
Description copied from interface: Mailer
Sends an encoded text-only mail message with full addressing information.

Specified by:
sendMail in interface Mailer
Parameters:
fromAddress - the sender's mail address.
replyToAddress - reply to addresses (see RFC822 for details).
senderAddress - sender addresses (see RFC822 for details).
toAddress - the receivers' mail addresses.
ccAddress - the addresses to receive carbon copy of this message.
bccAddress - the addresses to receive blind carbon copy of this message.
subject - the subject of the mail.
messageBody - the mail body as text.
encoding - the charset to be applied.
Throws:
LogException - if the addresses cannot be parsed or other problems in setting the data.

run

public void run()
Runs in the background message thread that does actual send mail operation using JavaMail.

Specified by:
run in interface Runnable

validateConfiguration

protected void validateConfiguration(Configuration config)
Description copied from class: DefaultConfigurable
Validates the configuration.

Overrides:
validateConfiguration in class DefaultConfigurable
Parameters:
config - the configuration.


Copyright © 2004 The Norther Organization. All rights reserved.