java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.AppenderBase<E>
ch.qos.logback.core.net.SMTPAppenderBase<E>
- All Implemented Interfaces:
Appender<E>,ContextAware,FilterAttachable<E>,LifeCycle
- Direct Known Subclasses:
SMTPAppender
An abstract class that provides support for sending events to an email
address.
See http://logback.qos.ch/manual/appenders.html#SMTPAppender for further documentation.
- Author:
- Ceki Gülcü, Sébastien Pennec
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Future<?> protected CyclicBufferTracker<E> protected Discriminator<E> protected EventEvaluator<E> static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected jakarta.mail.SessionFields inherited from class ch.qos.logback.core.AppenderBase
name, startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidPerform SMTPAppender specific appending actions, delegating some of them to a subclass and checking if the event triggers an e-mail to be sent.booleanThis method determines if there is a sense in attempting to append.protected abstract booleaneventMarksEndOfLife(E eventObject) protected abstract voidfillBuffer(CyclicBuffer<E> cb, StringBuffer sbuf) getFrom()Returns value of the From option.Returns value of the SMTPHost option.Alias for getSmtpHost().intSeesetSmtpPort(int)intAlias forgetSmtpPort()Returns value of the Subject option.Returns value of the toList option.booleanbooleanbooleanisSSL()booleanprotected abstract PatternLayoutBase<E> makeNewToPatternLayout(String toPattern) makeSubjectLayout(String subjectStr) return a layout for the subject string as appropriate for the module.protected voidsendBuffer(CyclicBuffer<E> cb, E lastEventObject) Send the contents of the cyclic buffer as an e-mail message.voidsetAsynchronousSending(boolean asynchronousSending) By default, SMTAppender transmits emails asynchronously.voidsetCharsetEncoding(String charsetEncoding) Set the character set encoding of the outgoing email messages.voidsetCyclicBufferTracker(CyclicBufferTracker<E> cbTracker) voidsetDiscriminator(Discriminator<E> discriminator) voidsetEvaluator(EventEvaluator<E> eventEvaluator) The EventEvaluator option takes a string value representing the name of the class implementing theEventEvaluatorinterface.voidThe From option takes a string value which should be an e-mail address of the sender.voidsetJndiLocation(String jndiLocation) Set the location where aSessionresource is located in JNDI.voidvoidsetLocalhost(String localhost) Set the "mail.smtp.localhost" property to the value passed as parameter to this method.voidsetPassword(String password) voidsetSessionViaJNDI(boolean sessionViaJNDI) If set to true, aSessionresource will be retrieved from JNDI.voidsetSmtpHost(String smtpHost) The smtpHost option takes a string value which should be the host name of the SMTP server that will send the e-mail message.voidsetSMTPHost(String smtpHost) Alias for smtpHostvoidsetSmtpPort(int port) The port where the SMTP server is running.voidsetSMTPPort(int port) Alias forsetSmtpPort(int).voidsetSSL(boolean ssl) voidsetSTARTTLS(boolean startTLS) voidsetSubject(String subject) The Subject option takes a string value which should be the subject of the e-mail message.voidsetUsername(String username) voidstart()Start the appendervoidstop()protected abstract voidsubAppend(CyclicBuffer<E> cb, E eventObject) protected voidupdateMimeMsg(jakarta.mail.internet.MimeMessage mimeMsg, CyclicBuffer<E> cb, E lastEventObject) Allows to extend classes to update mime message (e.g.: Add headers)Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
MAIL_SMTP_HOST_PK
- See Also:
-
MAIL_SMTP_PORT_PK
- See Also:
-
MAIL_SMTP_LOCALHOST_PK
- See Also:
-
MAIL_SMTP_AUTH_PK
- See Also:
-
MAIL_SMTP_STARTTLS_ENABLE_PK
- See Also:
-
MAIL_TRANSPORT_PROTOCOL_PK
- See Also:
-
MAIL_SMTP_SSL_ENABLE_PK
- See Also:
-
subjectLayout
-
layout
-
asynchronousSendingFuture
-
session
-
eventEvaluator
-
discriminator
-
cbTracker
-
-
Constructor Details
-
SMTPAppenderBase
public SMTPAppenderBase()
-
-
Method Details
-
makeSubjectLayout
return a layout for the subject string as appropriate for the module. If the subjectStr parameter is null, then a default value for subjectStr should be used.- Parameters:
subjectStr-- Returns:
- a layout as appropriate for the module
-
start
-
append
Perform SMTPAppender specific appending actions, delegating some of them to a subclass and checking if the event triggers an e-mail to be sent.- Specified by:
appendin classAppenderBase<E>
-
eventMarksEndOfLife
-
subAppend
-
checkEntryConditions
This method determines if there is a sense in attempting to append.It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the boolean value
falseis returned. -
stop
-
getToList
Returns value of the toList option. -
updateMimeMsg
protected void updateMimeMsg(jakarta.mail.internet.MimeMessage mimeMsg, CyclicBuffer<E> cb, E lastEventObject) Allows to extend classes to update mime message (e.g.: Add headers) -
sendBuffer
Send the contents of the cyclic buffer as an e-mail message. -
fillBuffer
-
getFrom
-
getSubject
Returns value of the Subject option. -
setFrom
-
setSubject
The Subject option takes a string value which should be the subject of the e-mail message. -
setSMTPHost
-
setSmtpHost
The smtpHost option takes a string value which should be the host name of the SMTP server that will send the e-mail message. -
getSMTPHost
Alias for getSmtpHost(). -
getSmtpHost
Returns value of the SMTPHost option. -
setSMTPPort
-
setSmtpPort
The port where the SMTP server is running. Default value is 25.- Parameters:
port-
-
getSMTPPort
-
getSmtpPort
-
getLocalhost
-
setLocalhost
Set the "mail.smtp.localhost" property to the value passed as parameter to this method.Useful in case the hostname for the client host is not fully qualified and as a consequence the SMTP server rejects the clients HELO/EHLO command.
- Parameters:
localhost-
-
getCyclicBufferTracker
-
setCyclicBufferTracker
-
getDiscriminator
-
setDiscriminator
-
isAsynchronousSending
-
setAsynchronousSending
By default, SMTAppender transmits emails asynchronously. For synchronous email transmission set asynchronousSending to 'false'.- Parameters:
asynchronousSending- determines whether sending is done asynchronously or not- Since:
- 1.0.4
-
addTo
-
makeNewToPatternLayout
-
getToAsListOfString
-
isSTARTTLS
-
setSTARTTLS
-
isSSL
-
setSSL
-
setEvaluator
The EventEvaluator option takes a string value representing the name of the class implementing theEventEvaluatorinterface. A corresponding object will be instantiated and assigned as the event evaluator for the SMTPAppender. -
getUsername
-
setUsername
-
getPassword
-
setPassword
-
getCharsetEncoding
- Returns:
- the charset encoding value
- See Also:
-
getJndiLocation
-
setJndiLocation
Set the location where aSessionresource is located in JNDI. Default value is "java:comp/env/mail/Session".- Parameters:
jndiLocation-- Since:
- 1.0.6
-
isSessionViaJNDI
-
setSessionViaJNDI
If set to true, aSessionresource will be retrieved from JNDI. Default is false.- Parameters:
sessionViaJNDI- whether to obtain a javax.mail.Session by JNDI- Since:
- 1.0.6
-
setCharsetEncoding
Set the character set encoding of the outgoing email messages. The default encoding is "UTF-8" which usually works well for most purposes.- Parameters:
charsetEncoding-
-
getLayout
-
setLayout
-