Top Description Inners Fields Constructors Methods
ch.qos.logback.core.net

public abstract Class SMTPAppenderBase<E>

extends AppenderBase<E>
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Date, .List, .Properties, java.util.concurrent.Future, jakarta.mail.Message, .Multipart, .Session, .Transport, jakarta.mail.internet.AddressException, .InternetAddress, .MimeBodyPart, .MimeMessage, .MimeMultipart, javax.naming.Context, ch.qos.logback.core.AppenderBase, .CoreConstants, .Layout, ch.qos.logback.core.boolex.EvaluationException, .EventEvaluator, ch.qos.logback.core.helpers.CyclicBuffer, ch.qos.logback.core.pattern.PatternLayoutBase, ch.qos.logback.core.sift.DefaultDiscriminator, .Discriminator, ch.qos.logback.core.spi.CyclicBufferTracker, ch.qos.logback.core.util.ContentTypeUtil, .JNDIUtil, .OptionHelper

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.

Authors
Ceki Gülcü, Sébastien Pennec

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv boolean
protected Future<?>
protected CyclicBufferTracker<E>
private String
pack-priv long
protected Discriminator<E>
pack-priv static InternetAddress[]
private int
protected EventEvaluator<E>
private String
private String
pack-priv long
protected Layout<E>
pack-priv String
pack-priv static final long
pack-priv String
protected Session
private boolean
private String
private int
private boolean
private boolean
protected Layout<E>
private String
private List<PatternLayoutBase<E>>
pack-priv String
Inherited from ch.qos.logback.core.AppenderBase:
namestarted

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
protected void
append(E eventObject)

Implements abstract ch.qos.logback.core.AppenderBase.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.
private Session
public boolean
checkEntryConditions()

This method determines if there is a sense in attempting to append.

protected abstract boolean
eventMarksEndOfLife(E eventObject)

protected abstract void
pack-priv InternetAddress
getAddress(String addressStr)

public String

Returns:

the charset encoding value
getCharsetEncoding
()

public CyclicBufferTracker<E>
public Discriminator<E>
public String
getFrom()

Returns value of the From option.

public String
public Layout<E>
public String
public String
public String
getSMTPHost()

Alias for getSmtpHost().

public String
getSmtpHost()

Returns value of the SMTPHost option.

public int
public int
public String
getSubject()

Returns value of the Subject option.

public List<String>
public List<PatternLayoutBase<E>>
getToList()

Returns value of the toList option.

public String
public boolean
public boolean
public boolean
public boolean
private Session
protected abstract PatternLayoutBase<E>
protected abstract Layout<E>

Returns:

a layout as appropriate for the module
makeSubjectLayout
(String subjectStr)

return a layout for the subject string as appropriate for the module.

private List<InternetAddress>
parseAddress(E event)

protected void
sendBuffer(CyclicBuffer<E> cb, E lastEventObject)

Send the contents of the cyclic buffer as an e-mail message.

public void
setAsynchronousSending(boolean
determines whether sending is done asynchronously or not
asynchronousSending
)

By default, SMTAppender transmits emails asynchronously.

public void
setCharsetEncoding(String charsetEncoding)

Set the character set encoding of the outgoing email messages.

public void
public void
setDiscriminator(Discriminator<E> discriminator)

public void
setEvaluator(EventEvaluator<E> eventEvaluator)

The EventEvaluator option takes a string value representing the name of the class implementing the EventEvaluator interface.

public void
setFrom(String from)

The From option takes a string value which should be an e-mail address of the sender.

public void
setJndiLocation(String jndiLocation)

Set the location where a jakarta.mail.Session resource is located in JNDI.

public void
setLayout(Layout<E> layout)

public void
setLocalhost(String localhost)

Set the "mail.smtp.localhost" property to the value passed as parameter to this method.

public void
setPassword(String password)

public void
setSessionViaJNDI(boolean
whether to obtain a javax.mail.Session by JNDI
sessionViaJNDI
)

If set to true, a jakarta.mail.Session resource will be retrieved from JNDI.

public void
setSMTPHost(String smtpHost)

Alias for smtpHost

public void
setSmtpHost(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.

public void
setSMTPPort(int port)

Alias for setSmtpPort.

public void
setSmtpPort(int port)

The port where the SMTP server is running.

public void
setSSL(boolean ssl)

public void
setSTARTTLS(boolean startTLS)

public void
setSubject(String subject)

The Subject option takes a string value which should be the subject of the e-mail message.

public void
setUsername(String username)

public void
public synchronized void
protected abstract void
subAppend(CyclicBuffer<E> cb, E eventObject)

protected void
updateMimeMsg(MimeMessage mimeMsg, CyclicBuffer<E> cb, E lastEventObject)

Allows to extend classes to update mime message (e.g.: Add headers)

Inherited from ch.qos.logback.core.AppenderBase:
addFilterclearAllFiltersdoAppendgetCopyOfAttachedFiltersListgetFilterChainDecisiongetNameisStartedsetNametoString

Field Detail

asynchronousSendingback to summary
pack-priv boolean asynchronousSending
asynchronousSendingFutureback to summary
protected Future<?> asynchronousSendingFuture
cbTrackerback to summary
protected CyclicBufferTracker<E> cbTracker
charsetEncodingback to summary
private String charsetEncoding
delayBetweenStatusMessagesback to summary
pack-priv long delayBetweenStatusMessages
discriminatorback to summary
protected Discriminator<E> discriminator
EMPTY_IA_ARRAYback to summary
pack-priv static InternetAddress[] EMPTY_IA_ARRAY
errorCountback to summary
private int errorCount
eventEvaluatorback to summary
protected EventEvaluator<E> eventEvaluator
fromback to summary
private String from
jndiLocationback to summary
private String jndiLocation
lastTrackerStatusPrintback to summary
pack-priv long lastTrackerStatusPrint
layoutback to summary
protected Layout<E> layout
localhostback to summary
pack-priv String localhost
MAX_DELAY_BETWEEN_STATUS_MESSAGESback to summary
pack-priv static final long MAX_DELAY_BETWEEN_STATUS_MESSAGES
passwordback to summary
pack-priv String password
sessionback to summary
protected Session session
sessionViaJNDIback to summary
private boolean sessionViaJNDI
smtpHostback to summary
private String smtpHost
smtpPortback to summary
private int smtpPort
sslback to summary
private boolean ssl
starttlsback to summary
private boolean starttls
subjectLayoutback to summary
protected Layout<E> subjectLayout
subjectStrback to summary
private String subjectStr
toPatternLayoutListback to summary
private List<PatternLayoutBase<E>> toPatternLayoutList
usernameback to summary
pack-priv String username

Constructor Detail

SMTPAppenderBaseback to summary
public SMTPAppenderBase()

Method Detail

addToback to summary
public void addTo(String to)
appendback to summary
protected void append(E eventObject)

Implements abstract ch.qos.logback.core.AppenderBase.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.

buildSessionFromPropertiesback to summary
private Session buildSessionFromProperties()
checkEntryConditionsback to summary
public boolean 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 false is returned.

eventMarksEndOfLifeback to summary
protected abstract boolean eventMarksEndOfLife(E eventObject)
fillBufferback to summary
protected abstract void fillBuffer(CyclicBuffer<E> cb, StringBuffer sbuf)
getAddressback to summary
pack-priv InternetAddress getAddress(String addressStr)
getCharsetEncodingback to summary
public String getCharsetEncoding()
Returns:String

the charset encoding value

See Also
setCharsetEncoding(String)
getCyclicBufferTrackerback to summary
public CyclicBufferTracker<E> getCyclicBufferTracker()
getDiscriminatorback to summary
public Discriminator<E> getDiscriminator()
getFromback to summary
public String getFrom()

Returns value of the From option.

getJndiLocationback to summary
public String getJndiLocation()
getLayoutback to summary
public Layout<E> getLayout()
getLocalhostback to summary
public String getLocalhost()
getPasswordback to summary
public String getPassword()
getSMTPHostback to summary
public String getSMTPHost()

Alias for getSmtpHost().

getSmtpHostback to summary
public String getSmtpHost()

Returns value of the SMTPHost option.

getSMTPPortback to summary
public int getSMTPPort()

Alias for getSmtpPort

getSmtpPortback to summary
public int getSmtpPort()

See setSmtpPort

getSubjectback to summary
public String getSubject()

Returns value of the Subject option.

getToAsListOfStringback to summary
public List<String> getToAsListOfString()
getToListback to summary
public List<PatternLayoutBase<E>> getToList()

Returns value of the toList option.

getUsernameback to summary
public String getUsername()
isAsynchronousSendingback to summary
public boolean isAsynchronousSending()
isSessionViaJNDIback to summary
public boolean isSessionViaJNDI()
isSSLback to summary
public boolean isSSL()
isSTARTTLSback to summary
public boolean isSTARTTLS()
lookupSessionInJNDIback to summary
private Session lookupSessionInJNDI()
makeNewToPatternLayoutback to summary
protected abstract PatternLayoutBase<E> makeNewToPatternLayout(String toPattern)
makeSubjectLayoutback to summary
protected abstract Layout<E> makeSubjectLayout(String subjectStr)

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.

Returns:Layout<E>

a layout as appropriate for the module

parseAddressback to summary
private List<InternetAddress> parseAddress(E event)
sendBufferback to summary
protected void sendBuffer(CyclicBuffer<E> cb, E lastEventObject)

Send the contents of the cyclic buffer as an e-mail message.

Annotations
@SuppressWarnings:null
setAsynchronousSendingback to summary
public void setAsynchronousSending(boolean asynchronousSending)

By default, SMTAppender transmits emails asynchronously. For synchronous email transmission set asynchronousSending to 'false'.

Parameters
asynchronousSending:boolean

determines whether sending is done asynchronously or not

Since
1.0.4
setCharsetEncodingback to summary
public void setCharsetEncoding(String charsetEncoding)

Set the character set encoding of the outgoing email messages. The default encoding is "UTF-8" which usually works well for most purposes.

setCyclicBufferTrackerback to summary
public void setCyclicBufferTracker(CyclicBufferTracker<E> cbTracker)
setDiscriminatorback to summary
public void setDiscriminator(Discriminator<E> discriminator)
setEvaluatorback to summary
public void setEvaluator(EventEvaluator<E> eventEvaluator)

The EventEvaluator option takes a string value representing the name of the class implementing the EventEvaluator interface. A corresponding object will be instantiated and assigned as the event evaluator for the SMTPAppender.

setFromback to summary
public void setFrom(String from)

The From option takes a string value which should be an e-mail address of the sender.

setJndiLocationback to summary
public void setJndiLocation(String jndiLocation)

Set the location where a jakarta.mail.Session resource is located in JNDI. Default value is "java:comp/env/mail/Session".

Since
1.0.6
setLayoutback to summary
public void setLayout(Layout<E> layout)
setLocalhostback to summary
public void setLocalhost(String localhost)

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.

setPasswordback to summary
public void setPassword(String password)
setSessionViaJNDIback to summary
public void setSessionViaJNDI(boolean sessionViaJNDI)

If set to true, a jakarta.mail.Session resource will be retrieved from JNDI. Default is false.

Parameters
sessionViaJNDI:boolean

whether to obtain a javax.mail.Session by JNDI

Since
1.0.6
setSMTPHostback to summary
public void setSMTPHost(String smtpHost)

Alias for smtpHost

setSmtpHostback to summary
public void setSmtpHost(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.

setSMTPPortback to summary
public void setSMTPPort(int port)

Alias for setSmtpPort.

setSmtpPortback to summary
public void setSmtpPort(int port)

The port where the SMTP server is running. Default value is 25.

setSSLback to summary
public void setSSL(boolean ssl)
setSTARTTLSback to summary
public void setSTARTTLS(boolean startTLS)
setSubjectback to summary
public void setSubject(String subject)

The Subject option takes a string value which should be the subject of the e-mail message.

setUsernameback to summary
public void setUsername(String username)
startback to summary
public void start()

Overrides ch.qos.logback.core.AppenderBase.start.

Implements ch.qos.logback.core.spi.LifeCycle.start.

Start the appender

stopback to summary
public synchronized void stop()

Overrides ch.qos.logback.core.AppenderBase.stop.

Implements ch.qos.logback.core.spi.LifeCycle.stop.

subAppendback to summary
protected abstract void subAppend(CyclicBuffer<E> cb, E eventObject)
updateMimeMsgback to summary
protected void updateMimeMsg(MimeMessage mimeMsg, CyclicBuffer<E> cb, E lastEventObject)

Allows to extend classes to update mime message (e.g.: Add headers)

ch.qos.logback.core.net back to summary

pack-priv Class SMTPAppenderBase.SenderRunnable

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv final CyclicBuffer<E>
pack-priv final E
e

Constructor Summary

AccessConstructor and Description
pack-priv
SenderRunnable(CyclicBuffer<E> cyclicBuffer, E e)

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cyclicBufferback to summary
pack-priv final CyclicBuffer<E> cyclicBuffer
eback to summary
pack-priv final E e

Constructor Detail

SenderRunnableback to summary
pack-priv SenderRunnable(CyclicBuffer<E> cyclicBuffer, E e)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.