title: Spring boot - sending emails with Logback
body: <p>I am trying to configure Logback to send emails whenever an exception (Logging level: ERROR) occurs. I have not been able to make it work so far so I would like to ask for your help with the configuration.</p>
  
  <p>I have a Spring boot application where some processing is done:</p>
  
  <pre><code>private void foo() {
   try {
    // do something
   } catch (Exception e) {
    log.error("Logging my exception");
   }
  }
  </code></pre>
  
  <p>I would like to trigger an email whenever this error is logged. I followed some <a href="http://maciejwalkowiak.pl/blog/2012/04/03/application-errors-notification-with-logback/">tutorials</a> and I added <strong>logback.xml</strong> and <strong>smtp-appender.xml</strong> to my <code>resources</code> directory:</p>
  
  <p><strong>logback.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;include resource="org/springframework/boot/logging/logback/base.xml" /&gt;
      &lt;include resource="smtp-appender.xml" /&gt;
      &lt;logger name="com.mycompany" level="DEBUG"&gt;
          &lt;appender-ref ref="SMTP" /&gt;
      &lt;/logger&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>smtp-appender.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;included&gt;
      &lt;appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender"&gt;
          &lt;smtpHost&gt;xxx&lt;/smtpHost&gt;
          &lt;username&gt;user&lt;/username&gt;
          &lt;password&gt;password&lt;/password&gt;
  
          &lt;to&gt;test@email.com&lt;/to&gt;
          &lt;from&gt;me@email.com&lt;/from&gt;
          &lt;subject&gt;testError&lt;/subject&gt;
  
          &lt;layout class="ch.qos.logback.classic.html.HTMLLayout" /&gt;
  
      &lt;/appender&gt;
  &lt;/included&gt;
  </code></pre>
  
  <p>I have setup local smtpserver on localhost via <code>sendmail</code>. I have also tried with AWS smtp server and Gmail. None of these services worked for me so far.</p>
  
  <p>The problem is that I do not receive any email after the exception and there is literally no output corresponding to the logback (besides the <code>log.error()</code> output, of course) which makes me think that the application does not even know about these config files...</p>
  
  <p>These are my maven dependencies in <strong>pom.xml</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.2.5.RELEASE&lt;/version&gt;
      &lt;relativePath /&gt;
      &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
          &lt;artifactId&gt;lombok&lt;/artifactId&gt;
          &lt;version&gt;1.16.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.json&lt;/groupId&gt;
          &lt;artifactId&gt;json&lt;/artifactId&gt;
          &lt;version&gt;20141113&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.mail&lt;/groupId&gt;
          &lt;artifactId&gt;mail&lt;/artifactId&gt;
          &lt;version&gt;1.4&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Any help would be highly appreciated.</p>