Class SmtpManager
java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.net.SmtpManager
- All Implemented Interfaces:
AutoCloseable
Manager for sending SMTP events.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classFactory data.private static classFactory to create the SMTP Manager.Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CyclicBuffer<LogEvent> private final SmtpManager.FactoryDataprivate static final SmtpManager.SMTPManagerFactoryprivate javax.mail.internet.MimeMessageprivate final javax.mail.SessionFields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSmtpManager(String name, javax.mail.Session session, javax.mail.internet.MimeMessage message, SmtpManager.FactoryData data) -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate void(package private) static StringcreateManagerName(String to, String cc, String bcc, String from, String replyTo, String subject, String protocol, String host, int port, String username, boolean isDebug, String filterName) Creates a unique-per-configuration name for an smtp manager using the specified the parameters.
Using such a name allows us to maintain singletons per unique configurations.private static javax.mail.internet.MimeMessagecreateMimeMessage(SmtpManager.FactoryData data, javax.mail.Session session, LogEvent appendEvent) protected voidencodeContent(byte[] bytes, String encoding, ByteArrayOutputStream out) protected byte[]encodeContentToBytes(byte[] rawBytes, String encoding) protected byte[]formatContentToBytes(LogEvent[] priorEvents, LogEvent appendEvent, Layout<?> layout) protected StringgetEncoding(byte[] rawBytes, String contentType) protected javax.mail.internet.InternetHeadersgetHeaders(String contentType, String encoding) protected javax.mail.internet.MimeMultipartgetMimeMultipart(byte[] encodedBytes, javax.mail.internet.InternetHeaders headers) static SmtpManagergetSmtpManager(Configuration config, String to, String cc, String bcc, String from, String replyTo, String subject, String protocol, String host, int port, String username, String password, boolean isDebug, String filterName, int numElements, SslConfiguration sslConfiguration) (package private) LogEvent[]voidsendEvents(Layout<?> layout, LogEvent appendEvent) Send the contents of the cyclic buffer as an e-mail message.protected voidsendMultipartMessage(javax.mail.internet.MimeMessage msg, javax.mail.internet.MimeMultipart mp) Deprecated.protected voidsendMultipartMessage(javax.mail.internet.MimeMessage msg, javax.mail.internet.MimeMultipart mp, String subject) protected voidwriteBuffer(LogEvent[] priorEvents, LogEvent appendEvent, Layout<?> layout, OutputStream out) private voidwriteContent(LogEvent[] priorEvents, LogEvent appendEvent, Layout<?> layout, ByteArrayOutputStream out) protected voidwriteFooter(Layout<?> layout, OutputStream out) protected voidwriteHeader(Layout<?> layout, OutputStream out) Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, releaseSub, stop, updateData
-
Field Details
-
FACTORY
-
session
private final javax.mail.Session session -
buffer
-
message
private volatile javax.mail.internet.MimeMessage message -
data
-
-
Constructor Details
-
SmtpManager
protected SmtpManager(String name, javax.mail.Session session, javax.mail.internet.MimeMessage message, SmtpManager.FactoryData data)
-
-
Method Details
-
createMimeMessage
private static javax.mail.internet.MimeMessage createMimeMessage(SmtpManager.FactoryData data, javax.mail.Session session, LogEvent appendEvent) throws javax.mail.MessagingException - Throws:
javax.mail.MessagingException
-
add
-
getSmtpManager
public static SmtpManager getSmtpManager(Configuration config, String to, String cc, String bcc, String from, String replyTo, String subject, String protocol, String host, int port, String username, String password, boolean isDebug, String filterName, int numElements, SslConfiguration sslConfiguration) -
createManagerName
static String createManagerName(String to, String cc, String bcc, String from, String replyTo, String subject, String protocol, String host, int port, String username, boolean isDebug, String filterName) Creates a unique-per-configuration name for an smtp manager using the specified the parameters.
Using such a name allows us to maintain singletons per unique configurations.- Returns:
- smtp manager name
-
sendEvents
Send the contents of the cyclic buffer as an e-mail message.- Parameters:
layout- The layout for formatting the events.appendEvent- The event that triggered the send.
-
removeAllBufferedEvents
LogEvent[] removeAllBufferedEvents() -
formatContentToBytes
protected byte[] formatContentToBytes(LogEvent[] priorEvents, LogEvent appendEvent, Layout<?> layout) throws IOException - Throws:
IOException
-
writeContent
private void writeContent(LogEvent[] priorEvents, LogEvent appendEvent, Layout<?> layout, ByteArrayOutputStream out) throws IOException - Throws:
IOException
-
writeHeader
- Throws:
IOException
-
writeBuffer
protected void writeBuffer(LogEvent[] priorEvents, LogEvent appendEvent, Layout<?> layout, OutputStream out) throws IOException - Throws:
IOException
-
getEncoding
-
encodeContentToBytes
protected byte[] encodeContentToBytes(byte[] rawBytes, String encoding) throws javax.mail.MessagingException, IOException - Throws:
javax.mail.MessagingExceptionIOException
-
encodeContent
protected void encodeContent(byte[] bytes, String encoding, ByteArrayOutputStream out) throws javax.mail.MessagingException, IOException - Throws:
javax.mail.MessagingExceptionIOException
-
getHeaders
-
getMimeMultipart
protected javax.mail.internet.MimeMultipart getMimeMultipart(byte[] encodedBytes, javax.mail.internet.InternetHeaders headers) throws javax.mail.MessagingException - Throws:
javax.mail.MessagingException
-
sendMultipartMessage
@Deprecated protected void sendMultipartMessage(javax.mail.internet.MimeMessage msg, javax.mail.internet.MimeMultipart mp) throws javax.mail.MessagingException Deprecated.Please use thesendMultipartMessage(MimeMessage, MimeMultipart, String)method instead.- Throws:
javax.mail.MessagingException
-
sendMultipartMessage
protected void sendMultipartMessage(javax.mail.internet.MimeMessage msg, javax.mail.internet.MimeMultipart mp, String subject) throws javax.mail.MessagingException - Throws:
javax.mail.MessagingException
-
connect
-
sendMultipartMessage(MimeMessage, MimeMultipart, String)method instead.