com.sun.mail.util.logging
Class MailHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by com.sun.mail.util.logging.MailHandler

public class MailHandler
extends Handler

Handler that formats log records as an email message.

This Handler will store a fixed number of log records used to generate a single email message. When the internal buffer reaches capacity, all log records are formatted and placed in an email which is sent to an email server. The code to manually setup this handler can be as simple as the following:

      Properties props = new Properties();
      props.put("mail.smtp.host", "my-mail-server");
      props.put("mail.to", "me@example.com");
      props.put("verify", "local");
      MailHandler h = new MailHandler(props);
      h.setLevel(Level.WARNING);
 

Configuration: The LogManager must define at least one or more recipient addresses and a mail host for outgoing email. The code to setup this handler via the logging properties can be as simple as the following:

      #Default MailHandler settings.
      com.sun.mail.util.logging.MailHandler.mail.smtp.host = my-mail-server
      com.sun.mail.util.logging.MailHandler.mail.to = me@example.com
      com.sun.mail.util.logging.MailHandler.level = WARNING
      com.sun.mail.util.logging.MailHandler.verify = local
 
All mail properties documented in the Java Mail API cascade to the LogManager by prefixing a key using the fully qualified class name of this MailHandler dot mail property. If the prefixed property is not found, then the mail property itself is searched in the LogManager. By default each MailHandler is initialized using the following LogManager configuration properties. If properties are not defined, or contain invalid values, then the specified default values are used.