title: Unable to send email on error from logback
body: <p>I am doing a POC to send email using logback and Java 8. On error we want to send an email to the user so i referred <a href="https://stackoverflow.com/questions/21833680/logback-smtpappender-not-sending-email">here</a> and my full configuration :</p>
  
  <pre><code>import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  public class App {
  
      private static final Logger logger = LoggerFactory.getLogger(App.class);
  
      public static void main(String[] args) throws InterruptedException {
          System.setProperty("java.net.preferIPv4Stack", "true");
          logger.trace("trace message");
          logger.warn("warn message");
          logger.error("error message, a very long error message!");
      }
  }
  </code></pre>
  
  <p>My logback.xml looks like below :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration debug="true" scan="true" scanPeriod="5 seconds"&gt;
   &lt;appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"&gt;
          &lt;smtpHost&gt;smtp.gmail.com&lt;/smtpHost&gt;
          &lt;username&gt;xxx@gmail.com&lt;/username&gt;
          &lt;password&gt;password&lt;/password&gt;
          &lt;smtpPort&gt;25&lt;/smtpPort&gt;
          &lt;to&gt;xxx@gmail.com&lt;/to&gt;
          &lt;from&gt;xxx@gmail.com&lt;/from&gt;
          &lt;STARTTLS&gt;true&lt;/STARTTLS&gt;
          &lt;asynchronousSending&gt;false&lt;/asynchronousSending&gt;
          &lt;subject&gt;Testing %logger
          {20}
  
          - %m&lt;/subject&gt;
          &lt;layout class="ch.qos.logback.classic.PatternLayout"&gt;
              &lt;pattern&gt;%d
                  {HH:mm:ss.SSS}
  
                  [%thread] %-5level %logger
                  {1}
  
                  -%msg%n
              &lt;/pattern&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
      &lt;root level="ERROR"&gt;
          &lt;appender-ref ref="EMAIL" /&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I see when I run main class the configuration is hanging. I do not see any error messages also. Kindly suggest.</p>
  
  <p><strong>UPDATE:</strong>
  OK ... I see that the port 25 or 587 throws the following error I have also referred <a href="https://stackoverflow.com/questions/6242838/log4j-failing-to-send-an-email-when-logging-an-error">this</a> :</p>
  
  <pre><code>20:07:02,050 |-ERROR in ch.qos.logback.classic.net.SMTPAppender[EMAIL] - Error occurred while sending e-mail notification. javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
    nested exception is:
      java.net.SocketException: Permission denied: connect
      at javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587
      at  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
      at  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
      at  at javax.mail.Service.connect(Service.java:317)
      at  at javax.mail.Service.connect(Service.java:176)
      at  at javax.mail.Service.connect(Service.java:125)
      at  at javax.mail.Transport.send0(Transport.java:194)
      at  at javax.mail.Transport.send(Transport.java:124)
      at  at ch.qos.logback.core.net.SMTPAppenderBase.sendBuffer(SMTPAppenderBase.java:388)
      at  at ch.qos.logback.core.net.SMTPAppenderBase.append(SMTPAppenderBase.java:212)
      at  at ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:82)
      at  at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
      at  at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
      at  at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
      at  at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
      at  at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
      at  at ch.qos.logback.classic.Logger.error(Logger.java:538)
      at  at com.email.example.App.main(App.java:18)
  Caused by: java.net.SocketException: Permission denied: connect
      at  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at  at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
      at  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      at  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      at  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at  at java.net.Socket.connect(Socket.java:589)
      at  at java.net.Socket.connect(Socket.java:538)
      at  at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321)
      at  at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
      at  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
      at  ... 16 common frames omitted
  </code></pre>
  
  <p>Am I missing something here? one point I want to mention is the from and to address are same, not sure if that matters.</p>