Mailer MBean

Introduction

The SMTP MBean is meant to be used to send emails from your JMX application. The MBean's class is mx4j.tools.mail.SMTP.

You can use it in basically two ways:

  • Directly by calling the sendMail method

  • By listening notifications, for instance from a Timer or Monitor

The usage of the MBean requires that you have JavaMail and the Java Activation Framework. The MBean has been tested with JavaMail 1.2 and JAF 1.0.1.

Configuration

The MBean has quite many attributes to work but as a minimum you should set up the serverHost and To. After that you can start sending emails.

If your server requires authentication, set the LoginToServer attribute to true and fill the ServerUserName and ServerPassword fields

You can also set the source address by setting the FromAddress field as well as the FromName field. The destination attributes can be set setting a comma separated list of addresses by using the To, Cc and Bcc attributes. The addresses are not checked until a mail is actually sent, but in case some are not well formed, to those who are will be sent anyway

To make the MBean to listen for notifications set the ObservedObject field. The SMTPMBean will register iteself as listener of that MBean and when a notification is received it will send the mail. If you set the NotificationName field, only notification names with that type will be valid to send a mail. For instance "javax.management.monitor.string.differ"

Keyword expanding

To make the content of the mail more customizable you can include keyword expansion on the Subject, and Content field. The keywords are special words set in between of $ signs. e.g. $date$. Those keywords will be replaced before the mail is sent, so you can get text containing more information. The recognized keywords are:

  • $date$ Expands to the current date formatted with locale format

  • $time$ Expands to the current time formatted with locale format

  • $datetime$ Expands to the current datetime formatted with locale format

  • $observed$ Expands to the observed MBean's ObjectName which triggered the mail

  • $notification$ Expands to the notification type which triggered the mail

  • $objectname$ Expands to the SMTPMBean's ObjectName