mx4j.tools.mail
Class SMTP

java.lang.Object
  extended bymx4j.tools.mail.SMTP
All Implemented Interfaces:
java.util.EventListener, javax.management.MBeanRegistration, javax.management.NotificationListener, SMTPMBean

public class SMTP
extends java.lang.Object
implements SMTPMBean, javax.management.NotificationListener, javax.management.MBeanRegistration

This MBean is meant to send a mail given certain situation. It may be used to listen to a monitor or timer and send a mail.

To use it you need to add to your classpath the mail.jar from the JavaMail API and the activation.jar from the Java Activation Framework.

Besides you need to configure all the required fields, at least the serverHost and To fields and if your server requires login also the serverUsername and serverPassword fields

The subject and content fields are subject to keyword expansions, i.e. some keyworks put between $ signs will be exapnded this can be used to give a more informative message. The current available expansions are

$date$ -> Current date formatted with locale format $time$ -> Current tim formatted with locale format $datetime$ -> Current date and time formatted with locale format $notification$ -> Notification type $observed$ -> ObjectName of the observed object $objectname$ -> This MBean's objectname

Version:
$Revision: 1.7 $

Constructor Summary
SMTP()
           
 
Method Summary
 java.lang.String getBCC()
          Gets a comma separated list of addresses set in the BCC field
 java.lang.String getCC()
          Gets a comma separated list of addresses set in the CC field
 java.lang.String getContent()
          Returns the content of the mail
 java.lang.String getFromAddress()
          Gets the from address attached to mails
 java.lang.String getFromName()
          Gets the from name presented on the mail
 java.lang.String getMimeType()
          Gets the MIME type set to the mail
 java.lang.String getNotificationName()
          Returns the notification which will trigger the mail sending
 javax.management.ObjectName getObservedObject()
          Gets the MBean's objectname which is being listened
 java.lang.String getServerHost()
          Gets the server's host as name or IP
 int getServerPort()
          Gets the server's port, by default is 25
 java.lang.String getServerUsername()
          Gets the username to log to the server
 java.lang.String getSubject()
          Gets the mail subject
 int getTimeout()
          Returns the timeout used when sending mails
 java.lang.String getTo()
          Gets a comma separated list of addresses set in the TO field
 void handleNotification(javax.management.Notification notification, java.lang.Object handback)
           
 boolean isLoginToServer()
          Indicates whether login to the SMTP server will be attpemted
 void postDeregister()
           
 void postRegister(java.lang.Boolean registrationDone)
           
 void preDeregister()
           
 javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
          Gathers some basic data
protected  void registerListener()
           
 void sendMail()
          This will directly execute the send mail.
 void setBCC(java.lang.String bccAddresses)
          Sets a comma separated list of address which will go in the BCC mail field
 void setCC(java.lang.String ccAddresses)
          Sets a comma separated list of address which will go in the CC mail field
 void setContent(java.lang.String content)
          Sets the content of the mail
 void setFromAddress(java.lang.String fromAddress)
          Sets the form address set to mail
 void setFromName(java.lang.String fromName)
          Sets the from name presented on the mail
 void setLoginToServer(boolean login)
          Sets whether to login to the SMTP server
 void setMimeType(java.lang.String mimeType)
          Sets the MIME type, by default it is text/plain
 void setNotificationName(java.lang.String notificationName)
          Sets the notification name which will trigger the mail sending.
 void setObservedObject(javax.management.ObjectName targetMBeanName)
          Sets the observed object.
 void setServerHost(java.lang.String host)
          Sets the server's host, it can be set as name or IP
 void setServerPassword(java.lang.String password)
          Sets server's passowrd, use with setLoginToServer(true) and setServerUsername
 void setServerPort(int port)
          Sets the server's port.
 void setServerUsername(java.lang.String username)
          Sets server's username, use with setLoginToServer(true)
 void setSubject(java.lang.String subject)
          Sets the mail's subject, by default is Empty subject.
 void setTimeout(int timeout)
          Sets the send timeout, by default it is 10 secs
 void setTo(java.lang.String toAddresses)
          Sets a comma separated list of address which will go in the TO mail field
protected  void unregisterListener()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMTP

public SMTP()
Method Detail

handleNotification

public void handleNotification(javax.management.Notification notification,
                               java.lang.Object handback)
Specified by:
handleNotification in interface javax.management.NotificationListener

sendMail

public void sendMail()
Description copied from interface: SMTPMBean
This will directly execute the send mail. It can be used to manually testing the MBean or direct execution

Specified by:
sendMail in interface SMTPMBean

getBCC

public java.lang.String getBCC()
Description copied from interface: SMTPMBean
Gets a comma separated list of addresses set in the BCC field

Specified by:
getBCC in interface SMTPMBean

setBCC

public void setBCC(java.lang.String bccAddresses)
Description copied from interface: SMTPMBean
Sets a comma separated list of address which will go in the BCC mail field

Specified by:
setBCC in interface SMTPMBean

setCC

public void setCC(java.lang.String ccAddresses)
Description copied from interface: SMTPMBean
Sets a comma separated list of address which will go in the CC mail field

Specified by:
setCC in interface SMTPMBean

getCC

public java.lang.String getCC()
Description copied from interface: SMTPMBean
Gets a comma separated list of addresses set in the CC field

Specified by:
getCC in interface SMTPMBean

getFromAddress

public java.lang.String getFromAddress()
Description copied from interface: SMTPMBean
Gets the from address attached to mails

Specified by:
getFromAddress in interface SMTPMBean

setFromAddress

public void setFromAddress(java.lang.String fromAddress)
Description copied from interface: SMTPMBean
Sets the form address set to mail

Specified by:
setFromAddress in interface SMTPMBean

setServerHost

public void setServerHost(java.lang.String host)
Description copied from interface: SMTPMBean
Sets the server's host, it can be set as name or IP

Specified by:
setServerHost in interface SMTPMBean

getServerHost

public java.lang.String getServerHost()
Description copied from interface: SMTPMBean
Gets the server's host as name or IP

Specified by:
getServerHost in interface SMTPMBean

setServerPort

public void setServerPort(int port)
Description copied from interface: SMTPMBean
Sets the server's port.

Specified by:
setServerPort in interface SMTPMBean

getServerPort

public int getServerPort()
Description copied from interface: SMTPMBean
Gets the server's port, by default is 25

Specified by:
getServerPort in interface SMTPMBean

setServerUsername

public void setServerUsername(java.lang.String username)
Description copied from interface: SMTPMBean
Sets server's username, use with setLoginToServer(true)

Specified by:
setServerUsername in interface SMTPMBean

getServerUsername

public java.lang.String getServerUsername()
Description copied from interface: SMTPMBean
Gets the username to log to the server

Specified by:
getServerUsername in interface SMTPMBean

setServerPassword

public void setServerPassword(java.lang.String password)
Description copied from interface: SMTPMBean
Sets server's passowrd, use with setLoginToServer(true) and setServerUsername

Specified by:
setServerPassword in interface SMTPMBean

setLoginToServer

public void setLoginToServer(boolean login)
Description copied from interface: SMTPMBean
Sets whether to login to the SMTP server

Specified by:
setLoginToServer in interface SMTPMBean

isLoginToServer

public boolean isLoginToServer()
Description copied from interface: SMTPMBean
Indicates whether login to the SMTP server will be attpemted

Specified by:
isLoginToServer in interface SMTPMBean

getFromName

public java.lang.String getFromName()
Description copied from interface: SMTPMBean
Gets the from name presented on the mail

Specified by:
getFromName in interface SMTPMBean

setFromName

public void setFromName(java.lang.String fromName)
Description copied from interface: SMTPMBean
Sets the from name presented on the mail

Specified by:
setFromName in interface SMTPMBean

getMimeType

public java.lang.String getMimeType()
Description copied from interface: SMTPMBean
Gets the MIME type set to the mail

Specified by:
getMimeType in interface SMTPMBean

setMimeType

public void setMimeType(java.lang.String mimeType)
Description copied from interface: SMTPMBean
Sets the MIME type, by default it is text/plain

Specified by:
setMimeType in interface SMTPMBean

getNotificationName

public java.lang.String getNotificationName()
Description copied from interface: SMTPMBean
Returns the notification which will trigger the mail sending

Specified by:
getNotificationName in interface SMTPMBean

setNotificationName

public void setNotificationName(java.lang.String notificationName)
Description copied from interface: SMTPMBean
Sets the notification name which will trigger the mail sending. If it is null any notification will trigger a mail

Specified by:
setNotificationName in interface SMTPMBean

getSubject

public java.lang.String getSubject()
Description copied from interface: SMTPMBean
Gets the mail subject

Specified by:
getSubject in interface SMTPMBean

setSubject

public void setSubject(java.lang.String subject)
Description copied from interface: SMTPMBean
Sets the mail's subject, by default is Empty subject. The subject field can contain keyword expansion

Specified by:
setSubject in interface SMTPMBean

getContent

public java.lang.String getContent()
Description copied from interface: SMTPMBean
Returns the content of the mail

Specified by:
getContent in interface SMTPMBean

setContent

public void setContent(java.lang.String content)
Description copied from interface: SMTPMBean
Sets the content of the mail

Specified by:
setContent in interface SMTPMBean

setTimeout

public void setTimeout(int timeout)
Description copied from interface: SMTPMBean
Sets the send timeout, by default it is 10 secs

Specified by:
setTimeout in interface SMTPMBean

getTimeout

public int getTimeout()
Description copied from interface: SMTPMBean
Returns the timeout used when sending mails

Specified by:
getTimeout in interface SMTPMBean

setObservedObject

public void setObservedObject(javax.management.ObjectName targetMBeanName)
Description copied from interface: SMTPMBean
Sets the observed object. It is expected that the observed MBean is a NotificationBroadcster On the contrary the MBean will not be listening to events

Specified by:
setObservedObject in interface SMTPMBean

getObservedObject

public javax.management.ObjectName getObservedObject()
Description copied from interface: SMTPMBean
Gets the MBean's objectname which is being listened

Specified by:
getObservedObject in interface SMTPMBean

getTo

public java.lang.String getTo()
Description copied from interface: SMTPMBean
Gets a comma separated list of addresses set in the TO field

Specified by:
getTo in interface SMTPMBean

setTo

public void setTo(java.lang.String toAddresses)
Description copied from interface: SMTPMBean
Sets a comma separated list of address which will go in the TO mail field

Specified by:
setTo in interface SMTPMBean

preRegister

public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                               javax.management.ObjectName name)
                                        throws java.lang.Exception
Gathers some basic data

Specified by:
preRegister in interface javax.management.MBeanRegistration
Throws:
java.lang.Exception

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Specified by:
postRegister in interface javax.management.MBeanRegistration

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Specified by:
preDeregister in interface javax.management.MBeanRegistration
Throws:
java.lang.Exception

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface javax.management.MBeanRegistration

registerListener

protected void registerListener()

unregisterListener

protected void unregisterListener()


Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.