## Send an email per transaction but only for certain users

Let Dave and Tata be software engineers working at a company called Fooware.com. As you might have guessed, Fooware.com sells foos. Yes, foos. Let Buscrit be a business critical back-end system running at Fooware.com. Buscrit is called by a number of applications to make business-critical transactions of various types.

We would like to allow Tata, a QA-engineer, to access the logging data generated by Buscrit as conveniently as possible. Tata could access the log files directly on the server where Buscrit runs. Let us assume that accessing the log files is impractical because one of the following conditions holds true:

1. Buscrit runs on several hosts and it is difficult to identify the host where a particular transaction was executed
2. Tata does not (or does not wish to) have access to the hosts where Byscrit runs
3. Buscrit is tested by half a dozen testers simultanesouly so that it is hard to indetify and track an individual transaction in the log files

Given the above circumstances, let us create a logback configuration so that Tata receives an email message containing the logs generated by a single transaction. We will later refine this configuration so that Tata will receive an email per transaction but only for the transactions she explicitly selects.

### Generating an email message containing the logs of a single transaction

We will be using `SMTPAppender` to generate emails containing logging data. Please refer to the appropriate section of the manual to familiarize yourself with `SMTPAppender`. is described in chapter on appenders describes

    <configuration scan="true" scanPeriod="3 seconds">

      <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />

      <appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
        <SMTPHost>NAME_OF_SMTP_HOST</SMTPHost>
        <To>...</To>
        <From>...</From>
        <layout class="ch.qos.logback.classic.html.HTMLLayout">
          <pattern>%date%level%logger{24}%msg</pattern>
        </layout>
        <evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
          <expression>
            marker != null  && marker.contains("SMTP_TRIGGER")
          </expression>
        </evaluator>
      </appender>

      <root level="DEBUG">
        <appender-ref ref="SMTP" />
      </root>

    </configuration>

     <appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
        <SMTPHost>NAME_OF_SMTP_HOST</SMTPHost>
        <To>com</To>
        <From></From>
        <layout class="ch.qos.logback.classic.html.HTMLLayout">
           <pattern>%date%level%logger{24}%msg</pattern>
        </layout>

        <discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
          <key>uuid</key>
          <defaultValue>default</defaultValue>
        </discriminator>

        <evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
          <expression>
            (mdc != null && mdc.get("txUser") != null &&
                 ((String) mdc.get("txUser")).contains("Mickey") )
            &&
            (marker != null  && marker.contains("SMTP_TRIGGER") )
          </expression>
        </evaluator>

        <discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
          <key>uuid</key>
          <defaultValue>default</defaultValue>
        </discriminator>

      </appender>