org.lexevs.logging
Class SimpleEmailAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.lexevs.logging.SimpleEmailAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class SimpleEmailAppender
extends org.apache.log4j.AppenderSkeleton

Simple SMTP Client that allows your Java App send emails. Uses Java Sockets to connect directly to an SMTP server. It supports sending of plain text or HTML emails. Bonus: Unlike many other Java SMTP Sockets examples, this one actually works.


Field Summary
protected  org.apache.log4j.helpers.CyclicBuffer _m_cb
          The _m_cb.
protected  org.apache.log4j.spi.TriggeringEventEvaluator _m_evaluator
          The _m_evaluator.
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
SimpleEmailAppender()
          Instantiates a new simple email appender.
SimpleEmailAppender(org.apache.log4j.spi.TriggeringEventEvaluator evaluator)
          Instantiates a new simple email appender.
 
Method Summary
protected  void append(org.apache.log4j.spi.LoggingEvent event)
           
protected  boolean checkEntryConditions()
          Check entry conditions.
 void close()
           
static void main(java.lang.String[] args)
          The main method.
 boolean requiresLayout()
           
 java.lang.String send(java.lang.String host, int port, java.lang.String to, java.lang.String from, java.lang.String subject, java.lang.String message)
          Sends an email.
 void setBufferSize(int bufferSize)
          Sets the buffer size.
 void setFrom(java.lang.String from)
          Sets the from.
 void setSMTPHost(java.lang.String smtpHost)
          Sets the sMTP host.
 void setSubject(java.lang.String subject)
          Sets the subject.
 void setTo(java.lang.String to)
          Sets the to.
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
activateOptions, addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_m_evaluator

protected org.apache.log4j.spi.TriggeringEventEvaluator _m_evaluator
The _m_evaluator.


_m_cb

protected org.apache.log4j.helpers.CyclicBuffer _m_cb
The _m_cb.

Constructor Detail

SimpleEmailAppender

public SimpleEmailAppender()
Instantiates a new simple email appender.


SimpleEmailAppender

public SimpleEmailAppender(org.apache.log4j.spi.TriggeringEventEvaluator evaluator)
Instantiates a new simple email appender.

Parameters:
evaluator - the evaluator
Method Detail

setTo

public void setTo(java.lang.String to)
Sets the to.

Parameters:
to - the new to

setFrom

public void setFrom(java.lang.String from)
Sets the from.

Parameters:
from - the new from

setSubject

public void setSubject(java.lang.String subject)
Sets the subject.

Parameters:
subject - the new subject

setSMTPHost

public void setSMTPHost(java.lang.String smtpHost)
Sets the sMTP host.

Parameters:
smtpHost - the new sMTP host

setBufferSize

public void setBufferSize(int bufferSize)
Sets the buffer size.

Parameters:
bufferSize - the new buffer size

send

public java.lang.String send(java.lang.String host,
                             int port,
                             java.lang.String to,
                             java.lang.String from,
                             java.lang.String subject,
                             java.lang.String message)
                      throws java.lang.Exception
Sends an email.

Parameters:
host - the host
port - the port
to - the to
from - the from
subject - the subject
message - the message
Returns:
The full SMTP conversation as a string.
Throws:
java.lang.Exception - the exception

append

protected void append(org.apache.log4j.spi.LoggingEvent event)
Specified by:
append in class org.apache.log4j.AppenderSkeleton

checkEntryConditions

protected boolean checkEntryConditions()
Check entry conditions.

Returns:
true, if successful

close

public void close()

requiresLayout

public boolean requiresLayout()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
The main method.

Parameters:
args - the arguments
Throws:
java.lang.Exception - the exception

Copyright: (c) 2004-2006 Mayo Foundation for Medical Education and Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the triple-shield Mayo logo are trademarks and service marks of MFMER.