How to send log to mail using log4j 2?

Logging to console and file is working correctly,but emails are not sending.

there are settings :

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn" name="MyApp" packages>
<appenders>

 <!-- SMTP appender -->
 <smtp name="Mail" subject="Logging" to="viacheslav.belyi@gmail.com" from="slavik58260849@gmail.com" 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">
</patternlayout></console>

</appenders>

<loggers>
 <root level="error">
 <appenderref ref="Mail">
 <appenderref ref="File">
 <appenderref ref="STDOUT">
</appenderref></appenderref></appenderref></root>

</loggers>
</configuration>


writes :
JavaFX Application Thread ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.SmtpAppender element for SMTP: java.lang.NoClassDefFoundError: javax/mail/MessagingException java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)

JavaFX Application Thread ERROR Null object returned for SMTP Appenders in.

if that documentation here : https://logging.apache.org/log4j/2.x/manual/append...
June 5th 19 at 21:14
1 answer
June 5th 19 at 21:16
Solution
Obviously not enough classes for working with SMTP.
I have worked to add 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>

Find more questions by tags JavaLoggingLog4j