Answer the question
In order to leave comments, you need to log in
How to send log to mail using log4j 2?
Logging to the console and the file works correctly, but it does not send letters.
there are these settings:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<!-- SMTP appender -->
<SMTP name="Mail" subject="Logging"
to="[email protected]" from= "[email protected]"
smtpHost="smtp.gmail.com" smtpPort="465" bufferSize="100"
smtpProtocol="smtps"
>
<PatternLayout>
<Pattern>%d{dd MM yyyy HH:mm:ss,SSS} - %msg%n</Pattern>
</PatternLayout>
</SMTP>
<!-- File appender -->
<File name="File" fileName="c:/logs/app.log">
<PatternLayout>
<Pattern>%d{dd MM yyyy HH:mm:ss,SSS} - %msg%n</Pattern>
</PatternLayout>
</File>
<!-- Console appender -->
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Mail"/>
<AppenderRef ref="File" />
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
Answer the question
In order to leave comments, you need to log in
Obviously, there are not enough classes to work with SMTP.
It worked for me with adding dependencies in Maven:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
<version>1.6.1</version>
</dependency>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question