atg.service.email
Class SMTPEmailSender

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.TimedOperationService
              extended by atg.service.email.SMTPEmailSender
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, EmailListener, EmailMessageSender, EmailSender, atg.service.email.TrackableEmailSender, java.util.EventListener

public class SMTPEmailSender
extends TimedOperationService
implements EmailListener, EmailSender, atg.service.email.TrackableEmailSender, EmailMessageSender

This service can be used to send an email message with the SMTP protocol


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
SMTPEmailSender()
          Constructs a SMTPEmailSender
 
Method Summary
 void closeConnection(javax.mail.Transport pTransport)
          Closes the connection identified by the Transport object.
 java.lang.String getCharSet()
          Returns the default charSet
 java.lang.String getDefaultBcc()
          Returns the default sender (Bcc:) field.
 java.lang.String getDefaultBody()
          Returns the default message body, that should be prepended to all emails
 java.lang.String getDefaultCc()
          Returns the default sender (Cc:) field.
 java.lang.String[] getDefaultExtraHeaders()
          Returns the default list of extra headers that should be used in the email (e.g.
 java.lang.String getDefaultFrom()
          Returns the default sender (From:) field.
 java.lang.String[] getDefaultRecipients()
          Returns the default list of Recipients that should receive email
 java.lang.String getDefaultSubject()
          Returns the default subject field.
 boolean getDummyMode()
          Returns whether this component is in dummy mode, i.e.
 java.lang.String getEmailHandlerHostName()
          Returns the SMTP host used to send email.
 int getEmailHandlerPort()
          Returns the SMTP port used to send email.
 java.lang.String[] getInvalidSenderExceptionTags()
           
 java.lang.String getPassword()
          Returns the password used to authenticate on the SMTP server.
 int getRetryConnectionCount()
           
 java.lang.String getSourceHostName()
          Returns the hostname from which the email is coming from
 boolean getTestMode()
          Returns whether this component is in test mode, i.e.
 java.lang.String getUsername()
          Returns the user name used to authenticate on the SMTP server.
 int getWaitForConnectionMillis()
           
static void main(java.lang.String[] arguments)
           
 javax.mail.Transport openConnection()
          Opens a connection to the mail server using a separate thread.
 void printMessage(javax.mail.Message pMessage)
           
 void printParts(javax.mail.Part p)
           
 void sendEmailEvent(EmailEvent pEvent)
          Takes the given event and sends if off as an email message
 void sendEmailMessage(javax.mail.Message pMessage)
          Sends an email message.
 void sendEmailMessage(javax.mail.Message pMessage, javax.mail.Transport pTransport)
          Sends an email message.
 void sendEmailMessage(java.lang.String pBody)
          Sends a message via SMTP with the given body, and using the default properties for the From, Recipients, and Subject fields.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String[] pRecipients, java.lang.String pSubject, java.lang.String pBody)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String[] pRecipients, java.lang.String pSubject, java.lang.String pBody, java.lang.String pExtraHeader)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String[] pRecipients, java.lang.String pSubject, java.lang.String pBody, java.lang.String[] pExtraHeaders)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String[] pRecipients, java.lang.String pSubject, java.lang.String pBody, java.lang.String[] pExtraHeaders, java.util.Map pTrackingData)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String pRecipient, java.lang.String pSubject, java.lang.String pBody)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String pRecipient, java.lang.String pSubject, java.lang.String pBody, java.lang.String pExtraHeader)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String pRecipient, java.lang.String pSubject, java.lang.String pBody, java.lang.String[] pExtraHeaders)
          Sends a message via SMTP with the given parameters.
 void sendEmailMessage(java.lang.String pFrom, java.lang.String pRecipient, java.lang.String pSubject, java.lang.String pBody, java.lang.String[] pExtraHeaders, java.util.Map pTrackingData)
          Sends a message via SMTP with the given parameters.
 void setCharSet(java.lang.String pCharSet)
          Sets the default charSet.
 void setDefaultBcc(java.lang.String pBcc)
          Sets the default sender (Bcc:) field.
 void setDefaultBody(java.lang.String pBody)
          Sets the default message body, that should be prepended to all emails
 void setDefaultCc(java.lang.String pCc)
          Sets the default sender (Cc:) field.
 void setDefaultExtraHeaders(java.lang.String[] pExtraHeaders)
          Sets the default list of extra headers that should be used in the email (e.g.
 void setDefaultFrom(java.lang.String pFrom)
          Sets the default sender (From:) field.
 void setDefaultRecipients(java.lang.String[] pRecipients)
          Sets the default list of Recipients that should receive email
 void setDefaultSubject(java.lang.String pSubject)
          Sets the default subject field.
 void setDummyMode(boolean pDummyMode)
          Sets this component in dummy mode, i.e.
 void setEmailHandlerHostName(java.lang.String pHost)
          Sets the SMTP host used to send email.
 void setEmailHandlerPort(int pPort)
          Sets the SMTP port used to send email.
 void setInvalidSenderExceptionTags(java.lang.String[] pInvalidSenderExceptionTags)
           
 void setPassword(java.lang.String pPassword)
          Sets the password used to authenticate on the SMTP server.
 void setRetryConnectionCount(int pRetryConnectionCount)
           
 void setSourceHostName(java.lang.String pHostName)
          Sets the hostname from which the email is coming from
 void setTestMode(boolean pTestMode)
          Sets this component in test mode, i.e.
 void setUsername(java.lang.String pUsername)
          Sets the user name used to authenticate on the SMTP server.
 void setWaitForConnectionMillis(int pWait)
           
 
Methods inherited from class atg.nucleus.TimedOperationService
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

SMTPEmailSender

public SMTPEmailSender()
Constructs a SMTPEmailSender

Method Detail

getInvalidSenderExceptionTags

public java.lang.String[] getInvalidSenderExceptionTags()

setInvalidSenderExceptionTags

public void setInvalidSenderExceptionTags(java.lang.String[] pInvalidSenderExceptionTags)

getDefaultRecipients

public java.lang.String[] getDefaultRecipients()
Returns the default list of Recipients that should receive email


setDefaultRecipients

public void setDefaultRecipients(java.lang.String[] pRecipients)
Sets the default list of Recipients that should receive email


getTestMode

public boolean getTestMode()
Returns whether this component is in test mode, i.e. it will not send messages but it will attempt to connect to the SMTP mail server and it will output messages and headers to standard error.

Returns:
true if this component is in test mode

setTestMode

public void setTestMode(boolean pTestMode)
Sets this component in test mode, i.e. it will not send messages but it will attempt to connect to the SMTP mail server and it will output messages and headers to standard error.

Parameters:
pTestMode - true if this component is to be in test mode

getDummyMode

public boolean getDummyMode()
Returns whether this component is in dummy mode, i.e. it will not send messages, it will not attempt to connect to the SMTP mail server but it will output messages and headers to standard error.

Returns:
true if this component is in dummy mode

setDummyMode

public void setDummyMode(boolean pDummyMode)
Sets this component in dummy mode, i.e. it will not send messages, it will attempt to connect to the SMTP mail server but it will output messages and headers to standard error.

Parameters:
pDummyMode - true if this component is to be in dummy mode

getCharSet

public java.lang.String getCharSet()
Returns the default charSet


setCharSet

public void setCharSet(java.lang.String pCharSet)
Sets the default charSet.


getDefaultFrom

public java.lang.String getDefaultFrom()
Returns the default sender (From:) field.


setDefaultFrom

public void setDefaultFrom(java.lang.String pFrom)
Sets the default sender (From:) field.


getDefaultCc

public java.lang.String getDefaultCc()
Returns the default sender (Cc:) field.


setDefaultCc

public void setDefaultCc(java.lang.String pCc)
Sets the default sender (Cc:) field.


getDefaultBcc

public java.lang.String getDefaultBcc()
Returns the default sender (Bcc:) field.


setDefaultBcc

public void setDefaultBcc(java.lang.String pBcc)
Sets the default sender (Bcc:) field.


getDefaultSubject

public java.lang.String getDefaultSubject()
Returns the default subject field.


setDefaultSubject

public void setDefaultSubject(java.lang.String pSubject)
Sets the default subject field.


getDefaultExtraHeaders

public java.lang.String[] getDefaultExtraHeaders()
Returns the default list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")


setDefaultExtraHeaders

public void setDefaultExtraHeaders(java.lang.String[] pExtraHeaders)
Sets the default list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")


getDefaultBody

public java.lang.String getDefaultBody()
Returns the default message body, that should be prepended to all emails


setDefaultBody

public void setDefaultBody(java.lang.String pBody)
Sets the default message body, that should be prepended to all emails


getEmailHandlerHostName

public java.lang.String getEmailHandlerHostName()
Returns the SMTP host used to send email. This defaults to the localhost's host name


setEmailHandlerHostName

public void setEmailHandlerHostName(java.lang.String pHost)
Sets the SMTP host used to send email.


getEmailHandlerPort

public int getEmailHandlerPort()
Returns the SMTP port used to send email. This defaults to 25.


setEmailHandlerPort

public void setEmailHandlerPort(int pPort)
Sets the SMTP port used to send email.
You should not need to change this property for standard SMTP configurations.


getUsername

public java.lang.String getUsername()
Returns the user name used to authenticate on the SMTP server. This defaults to no user name.

Returns:
user name used to authenticate on the SMTP server

setUsername

public void setUsername(java.lang.String pUsername)
Sets the user name used to authenticate on the SMTP server.

Parameters:
pUsername - user name used to authenticate on the SMTP server

getPassword

public java.lang.String getPassword()
Returns the password used to authenticate on the SMTP server. This defaults to no password.

Returns:
password used to authenticate on the SMTP server

setPassword

public void setPassword(java.lang.String pPassword)
Sets the password used to authenticate on the SMTP server.

Parameters:
pPassword - password used to authenticate on the SMTP server

getSourceHostName

public java.lang.String getSourceHostName()
Returns the hostname from which the email is coming from


setSourceHostName

public void setSourceHostName(java.lang.String pHostName)
Sets the hostname from which the email is coming from


getRetryConnectionCount

public int getRetryConnectionCount()

setRetryConnectionCount

public void setRetryConnectionCount(int pRetryConnectionCount)

getWaitForConnectionMillis

public int getWaitForConnectionMillis()

setWaitForConnectionMillis

public void setWaitForConnectionMillis(int pWait)

sendEmailMessage

public void sendEmailMessage(java.lang.String pBody)
                      throws EmailException
Sends a message via SMTP with the given body, and using the default properties for the From, Recipients, and Subject fields. The message content is prepended by any value for the default body property.

Parameters:
pBody - The message content
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String pRecipient,
                             java.lang.String pSubject,
                             java.lang.String pBody)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface EmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipient - The recipient that should receive the message
pSubject - Subject line of the email message
pBody - The message content
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String pRecipient,
                             java.lang.String pSubject,
                             java.lang.String pBody,
                             java.lang.String pExtraHeader)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface EmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipient - The recipient that should receive the message
pSubject - Subject line of the email message
pBody - The message content
pExtraHeader - An extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String[] pRecipients,
                             java.lang.String pSubject,
                             java.lang.String pBody)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface EmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipients - The list of recipients that should receive email
pSubject - Subject line of the email message
pBody - The message content
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String pRecipient,
                             java.lang.String pSubject,
                             java.lang.String pBody,
                             java.lang.String[] pExtraHeaders)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface EmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipient - The recipient that should receive the message
pSubject - Subject line of the email message
pBody - The message content
pExtraHeaders - The list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String[] pRecipients,
                             java.lang.String pSubject,
                             java.lang.String pBody,
                             java.lang.String pExtraHeader)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface EmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipients - The list of recipients that should receive email
pSubject - Subject line of the email message
pBody - The message content
pExtraHeader - An extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String[] pRecipients,
                             java.lang.String pSubject,
                             java.lang.String pBody,
                             java.lang.String[] pExtraHeaders)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface EmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipients - The list of recipients that should receive email
pSubject - Subject line of the email message
pBody - The message content
pExtraHeaders - The list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String pRecipient,
                             java.lang.String pSubject,
                             java.lang.String pBody,
                             java.lang.String[] pExtraHeaders,
                             java.util.Map pTrackingData)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface atg.service.email.TrackableEmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipient - The recipient that should receive the message
pSubject - Subject line of the email message
pBody - The message content
pExtraHeaders - The list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")
pTrackingData - NV pair data to associate with the out-bound email.
Throws:
EmailException - if there is any problem while sending mail

sendEmailMessage

public void sendEmailMessage(java.lang.String pFrom,
                             java.lang.String[] pRecipients,
                             java.lang.String pSubject,
                             java.lang.String pBody,
                             java.lang.String[] pExtraHeaders,
                             java.util.Map pTrackingData)
                      throws EmailException
Sends a message via SMTP with the given parameters. The message content is prepended by any value for the default body property.

Specified by:
sendEmailMessage in interface atg.service.email.TrackableEmailSender
Parameters:
pFrom - Whom the mail is coming from
pRecipients - The list of recipients that should receive email
pSubject - Subject line of the email message
pBody - The message content
pExtraHeaders - The list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")
pTrackingData - NV pair data to associate with the out-bound email.
Throws:
EmailException - if there is any problem while sending mail

openConnection

public javax.mail.Transport openConnection()
                                    throws EmailException
Opens a connection to the mail server using a separate thread.

Specified by:
openConnection in interface EmailMessageSender
Returns:
Transport object representing the open connection
Throws:
EmailException - if the connection could not be opened

sendEmailMessage

public void sendEmailMessage(javax.mail.Message pMessage,
                             javax.mail.Transport pTransport)
                      throws EmailException
Sends an email message. The parameters of the email are specified within the Message object. The Transport object identifies the connection over which the message will be sent; the connection must have already been opened.

Specified by:
sendEmailMessage in interface EmailMessageSender
Throws:
EmailException - if the connection is not open, or if the message could not be sent

sendEmailMessage

public void sendEmailMessage(javax.mail.Message pMessage)
                      throws EmailException
Sends an email message. The parameters of the email are specified within the Message object. A new connection to the mail server will be opened, the message sent, and the connection closed.

Specified by:
sendEmailMessage in interface EmailMessageSender
Throws:
EmailException - if the message could not be sent

closeConnection

public void closeConnection(javax.mail.Transport pTransport)
                     throws EmailException
Closes the connection identified by the Transport object.

Specified by:
closeConnection in interface EmailMessageSender
Throws:
EmailException - if the connection could not be closed

sendEmailEvent

public void sendEmailEvent(EmailEvent pEvent)
                    throws EmailException
Takes the given event and sends if off as an email message

Specified by:
sendEmailEvent in interface EmailListener
Throws:
EmailException - if the email could not be sent

printMessage

public void printMessage(javax.mail.Message pMessage)

printParts

public void printParts(javax.mail.Part p)

main

public static void main(java.lang.String[] arguments)