////
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
////

[#smtpappender]
= SmtpAppender

The `SmtpAppender` sends log events via email using the Simple Mail Transfer Protocol (SMTP).
This appender is useful for sending email notifications when certain events occur, such as errors or critical failures in your application.

The following example shows how to configure the `SmtpAppender` to deliver log events via SMTP email.
The `To`, `From`, `Subject` and `SmtpHost` are required parameters.
This example shows how to deliver only significant events.

A LevelEvaluator is specified with a threshold of WARN.
This means that an email will be sent for each WARN or higher level message that is logged.
Each email will also contain up to 512 (BufferSize) previous messages of any level to provide context.

Messages not sent will be discarded.

[source,xml]
----
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="to@example.com" />
  <from value="from@example.com" />
  <subject value="test logging message" />
  <smtpHost value="smtp.example.com" />
  <bufferSize value="512" />
  <lossy value="true" />
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="WARN"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline%newline%newline" />
  </layout>
</appender>
----

This example shows how to configure the `SmtpAppender` to deliver all messages in emails with 512 `bufferSize` messages per email.

[source,xml]
----
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="to@example.com" />
  <from value="from@example.com" />
  <subject value="test logging message" />
  <smtpHost value="smtp.example.com" />
  <bufferSize value="512" />
  <lossy value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline%newline%newline" />
  </layout>
</appender>
----

This example shows a more verbose formatting layout for the mail messages.

[source,xml]
----
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender,log4net">
  <to value="to@example.com" />
  <from value="from@example.com" />
  <subject value="test logging message" />
  <smtpHost value="smtp.example.com" />
  <bufferSize value="512" />
  <lossy value="false" />
  <evaluator type="log4net.Core.LevelEvaluator,log4net">
    <threshold value="WARN" />
  </evaluator>
  <layout type="log4net.Layout.PatternLayout,log4net">
    <conversionPattern value="%property{log4net:HostName} :: %level :: %message %newlineLogger: %logger%newlineThread: %thread%newlineDate: %date%newline%newline" />
  </layout>
</appender>
----