org.liquidsite.util.mail
Class MailQueue

java.lang.Object
  extended byorg.liquidsite.util.mail.MailQueue

public class MailQueue
extends java.lang.Object

An outgoing email queue. This class is used for storing outgoing email messages for before being sent. Normally this queue should be empty, as queueing is performed in the receiving SMTP server. This queue is only used to reduce the reponse latency when processing web requests. The actual sending of the mails should be performed by a background thread.


Method Summary
 void add(MailMessage message)
          Adds a new message to the queue.
 java.lang.String getFooter()
          Returns the current mail footer.
 java.lang.String getHeader()
          Returns the current mail header.
static MailQueue getInstance()
          Returns the mail queue instance.
 void initialize(java.lang.String host, java.lang.String user, java.lang.String from)
          Initializes this mail queue.
 void process()
          Processes the mail messages in the queue.
 void setFooter(java.lang.String footer)
          Sets the mail footer.
 void setHeader(java.lang.String header)
          Sets the mail header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MailQueue getInstance()
Returns the mail queue instance.

Returns:
the mail queue instance

initialize

public void initialize(java.lang.String host,
                       java.lang.String user,
                       java.lang.String from)
Initializes this mail queue.

Parameters:
host - the mail host, or null for "localhost"
user - the mail user, or null for none
from - the mail from address, or null for none

getHeader

public java.lang.String getHeader()
Returns the current mail header.

Returns:
the current mail header

setHeader

public void setHeader(java.lang.String header)
Sets the mail header.

Parameters:
header - the new header, or null for default

getFooter

public java.lang.String getFooter()
Returns the current mail footer.

Returns:
the current mail footer

setFooter

public void setFooter(java.lang.String footer)
Sets the mail footer.

Parameters:
footer - the new footer, or null for default

add

public void add(MailMessage message)
         throws MailMessageException
Adds a new message to the queue. This method is thread-safe.

Parameters:
message - the message to add
Throws:
MailMessageException - if the message wasn't valid or if the queue was full

process

public void process()
             throws MailTransportException
Processes the mail messages in the queue. If the queue is empty, nothing is done. The messages are removed from the queue only if sent correctly or if they are invalid. On mail transport error, the mail messages will remain in the queue.

Throws:
MailTransportException - if the mail transport couldn't be initialized correctly