
Author: ceki Date: Wed Oct 15 00:45:06 2008 New Revision: 1831 Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/gmailSSL.xml logback/trunk/logback-examples/src/main/java/chapter4/mail/gmailSTARTTLS.xml Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppender_SubethaSMTPTest.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java logback/trunk/logback-site/src/site/pages/manual/appenders.html logback/trunk/logback-site/src/site/pages/news.html Log: LBCORE-17 Added documentation and test cases for STARTTLS and SSL support. Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppender_SubethaSMTPTest.java ============================================================================== --- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppender_SubethaSMTPTest.java (original) +++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppender_SubethaSMTPTest.java Wed Oct 15 00:45:06 2008 @@ -234,7 +234,7 @@ MessageListenerAdapter mla = (MessageListenerAdapter)wiser.getServer().getMessageHandlerFactory(); mla.setAuthenticationHandlerFactory(new TrivialAuthHandlerFactory()); - smtpAppender.setStartTLS(true); + smtpAppender.setSTARTTLS(true); smtpAppender.setUsername("xx"); smtpAppender.setPassword("xx"); @@ -259,7 +259,7 @@ smtpAppender.setSMTPPort(587); smtpAppender.addTo("XXX@gmail.com"); - smtpAppender.setStartTLS(true); + smtpAppender.setSTARTTLS(true); smtpAppender.setUsername("XXX@gmail.com"); smtpAppender.setPassword("XXX"); @@ -280,7 +280,7 @@ smtpAppender.setSMTPPort(465); smtpAppender.addTo("XXX@gmail.com"); - smtpAppender.setSsl(true); + smtpAppender.setSSL(true); smtpAppender.setUsername("XXX@gmail.com"); smtpAppender.setPassword("XXX"); Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java Wed Oct 15 00:45:06 2008 @@ -58,7 +58,7 @@ private String subjectStr = null; private String smtpHost; private int smtpPort = 25; - private boolean startTLS = false; + private boolean starttls = false; private boolean ssl = false; String username; @@ -96,14 +96,14 @@ props.put("mail.smtp.auth", "true"); } - if (isStartTLS() && isSsl()) { + if (isSTARTTLS() && isSSL()) { addError("Both SSL and StartTLS cannot be enabled simultaneously"); } else { - if (isStartTLS()) { + if (isSTARTTLS()) { props.setProperty("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); } - if (isSsl()) { + if (isSSL()) { String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; props.put("mail.smtp.socketFactory.port", Integer.toString(smtpPort)); props.put("mail.smtp.socketFactory.class", SSL_FACTORY); @@ -358,19 +358,19 @@ this.msg = msg; } - public boolean isStartTLS() { - return startTLS; + public boolean isSTARTTLS() { + return starttls; } - public void setStartTLS(boolean startTLS) { - this.startTLS = startTLS; + public void setSTARTTLS(boolean startTLS) { + this.starttls = startTLS; } - public boolean isSsl() { + public boolean isSSL() { return ssl; } - public void setSsl(boolean ssl) { + public void setSSL(boolean ssl) { this.ssl = ssl; } Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/gmailSSL.xml ============================================================================== --- (empty file) +++ logback/trunk/logback-examples/src/main/java/chapter4/mail/gmailSSL.xml Wed Oct 15 00:45:06 2008 @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<configuration> + + <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> + <SMTPHost>smtp.gmail.com</SMTPHost> + <SMTPPort>465</SMTPPort> + <SSL>true</SSL> + <Username>USERNAME</Username> + <Password>PASSWORD</Password> + + + <To>EMAIL-DESTINATION</To> + <To>ANOTHER_EMAIL_DESTINATION</To> <!-- a second destination is optional --> + <From>SENDER-EMAIL</From> + <Subject>TESTING: %logger{20} - %m</Subject> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern>%date %-5level %logger - %message%n</Pattern> + </layout> + </appender> + + <root> + <level value="debug"/> + <appender-ref ref="EMAIL" /> + </root> +</configuration> Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/gmailSTARTTLS.xml ============================================================================== --- (empty file) +++ logback/trunk/logback-examples/src/main/java/chapter4/mail/gmailSTARTTLS.xml Wed Oct 15 00:45:06 2008 @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<configuration> + + <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> + <SMTPHost>smtp.gmail.com</SMTPHost> + <SMTPPort>587</SMTPPort> + <STARTTLS>true</STARTTLS> + <Username>USERNAME</Username> + <Password>PASSWORD</Password> + + <To>EMAIL-DESTINATION</To> + <To>ANOTHER_EMAIL_DESTINATION</To> <!-- a second destination is optional --> + <From>SENDER-EMAIL</From> + <Subject>TESTING: %logger{20} - %m</Subject> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern>%date %-5level %logger - %message%n</Pattern> + </layout> + </appender> + + <root> + <level value="debug"/> + <appender-ref ref="EMAIL" /> + </root> +</configuration> Modified: logback/trunk/logback-site/src/site/pages/manual/appenders.html ============================================================================== --- logback/trunk/logback-site/src/site/pages/manual/appenders.html (original) +++ logback/trunk/logback-site/src/site/pages/manual/appenders.html Wed Oct 15 00:45:06 2008 @@ -1920,14 +1920,14 @@ <td><code>String</code></td> <td>The host name of the SMTP server. This parameter is mandatory.</td> </tr> - + <tr class="alt"> <td><b><span class="option">SMTPPort</span></b></td> <td><code>int</code></td> <td>The port where the SMTP server is listening. Defaults to 25.</td> </tr> - + <tr> <td><b><span class="option">To</span></b></td> <td><code>String</code></td> @@ -1964,46 +1964,79 @@ </p> <p>By default, this option is set to "%logger{20} - %m".</p> - </td> - </tr> - <tr class="alt"> - <td><b><span class="option">BufferSize</span></b></td> - <td><code>int</code></td> - <td> - The <span class="option">BufferSize</span> option takes a positive - integer representing the maximum number of logging events to collect in a - cyclic buffer. When the <span class="option">BufferSize</span> is reached, - oldest events are deleted as new events are added to the buffer. - The default size of the cyclic buffer is 512. - </td> - </tr> - <tr > - <td><b><span class="option">Evaluator</span></b></td> - <td><code>String</code></td> - <td> - <p>This option is declared by creating a new <code><EventEvaluator/></code> - element. The name of the class that the user wishes to use as the - <code>SMTPAppender</code>'s <code>Evaluator</code> can be given - by adding an attribute to the newly created element. - </p> - - <p>More details about the use of event evaluators with - <code>SMTPAppender</code> follow further down this document. - </p> - - <p>In the absence of this option, <code>SMTPAppender</code> is - assigned a default event evaluator which triggers email - transmission as a response to any event of level - <em>ERROR</em> or higher. - </p> - - <p><code>EventEvaluator</code> objects are subclasses of the - <code>JaninoEventEvaluatorBase</code> which depends on - Janino. See the <a href="../dependencies.html">dependencies - page</a> for more information. - </p> - </td> - </tr> + </td> + </tr> + <tr class="alt"> + <td><b><span class="option">BufferSize</span></b></td> + <td><code>int</code></td> + <td> + The <span class="option">BufferSize</span> option takes a positive + integer representing the maximum number of logging events to collect in a + cyclic buffer. When the <span class="option">BufferSize</span> is reached, + oldest events are deleted as new events are added to the buffer. + The default size of the cyclic buffer is 512. + </td> + </tr> + <tr > + <td><b><span class="option">Evaluator</span></b></td> + <td><code>String</code></td> + <td> + <p>This option is declared by creating a new <code><EventEvaluator/></code> + element. The name of the class that the user wishes to use as the + <code>SMTPAppender</code>'s <code>Evaluator</code> can be given + by adding an attribute to the newly created element. + </p> + + <p>More details about the use of event evaluators with + <code>SMTPAppender</code> follow further down this document. + </p> + + <p>In the absence of this option, <code>SMTPAppender</code> is + assigned a default event evaluator which triggers email + transmission as a response to any event of level + <em>ERROR</em> or higher. + </p> + + <p><code>EventEvaluator</code> objects are subclasses of the + <code>JaninoEventEvaluatorBase</code> which depends on + Janino. See the <a href="../dependencies.html">dependencies + page</a> for more information. + </p> + </td> + </tr> + <tr class="alt"> + <td><b><span class="option">Username</span></b></td> + <td><code>String</code></td> + <td>The username value to use during plain user/password + authentication. By default, this parameter is null. + </td> + </tr> + <tr > + <td><b><span class="option">Password</span></b></td> + <td><code>String</code></td> + <td>The password value to use for plain user/password + authentication. By default, this parameter is null. + </td> + </tr> + <tr class="alt"> + <td><b><span class="option">STARTTLS</span></b></td> + <td><code>boolean</code></td> + <td>If this parameter is set to true, then this appender will + issue the STARTTLS command (if the server supports it) causing + the connection to switch to SSL. Note that the connection is + initally non-encrypted. By default, this parameter is set to + false. + </td> + </tr> + <tr > + <td><b><span class="option">SSL</span></b></td> + <td><code>boolean</code></td> + <td>If this parameter is set to true, then this appender will + open an SSL conneciton to the server. By default, this + parameter is set to false. + </td> + </tr> + </table> <p>The SMTPAppender keeps only the last <span @@ -2230,26 +2263,63 @@ </root> </configuration></pre></div> + + <h3>Authentication/STARTTLS/SSL</h3> + + <p>SMTPAppender supports plain user/password authentication as + well as both STARTTLS and SSL. + </p> + + <p>The next example shows you how to configure SMTPAppender for + gmail with SSL. </p> + +<em>Example 4.13: <code>SMTPAppender</code> to GMAIL using SSL (logback-examples/src/main/java/chapter4/mail/gmailSSL.xml)</em> + +<div class="source"><pre><configuration> + <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> + <b><SMTPHost>smtp.gmail.com</SMTPHost> + <SMTPPort>465</SMTPPort> + <SSL>true</SSL> + <Username>USERNAME@gmail.com</Username> + <Password>PASSWORD</Password></b> + <To>${to}</To> + <From>${from}</From> + <layout class="ch.qos.logback.classic.html.HTMLLayout"/> + </appender> + + <root> + <level value ="debug"/> + <appender-ref ref="EMAIL" /> + </root> +</configuration></pre></div> + + <p>For a STARTTLS with gmail refer to the configuration file + <em>logback-examples/src/main/java/chapter4/mail/gmailSTARTTLS.xml)</em> + + </p> <a name="DBAppender"></a> <h3>DBAppender</h3> - <p> - The <a href="../xref/ch/qos/logback/classic/db/DBAppender.html"><code>DBAppender</code></a> - inserts loggin events into three database tables in a format - independent of the Java programming language. - </p> - <p> - These three tables are <em>logging_event</em>, <em>logging_event_property</em> and - <em>logging_event_exception</em>. They all must exist before <code>DBAppender</code> - can be used. Logback ships with SQL scripts that will create the tables. - They can be found in the found in the - <em>logback-classic/src/main/java/ch/qos/logback/classic/db/dialect</em> directory. There - is a specific script for each of the most popular database systems. - If the script for your particular type of database system is missing, it should be - quite easy to write one, taking example on the already existing scripts. If - you send them to us, we will gladly include missing scripts in future releases. + <p>The <a + href="../xref/ch/qos/logback/classic/db/DBAppender.html"><code>DBAppender</code></a> + inserts loggin events into three database tables in a format + independent of the Java programming language. + </p> + + <p>These three tables are <em>logging_event</em>, + <em>logging_event_property</em> and + <em>logging_event_exception</em>. They all must exist before + <code>DBAppender</code> can be used. Logback ships with SQL + scripts that will create the tables. They can be found in the + found in the + <em>logback-classic/src/main/java/ch/qos/logback/classic/db/dialect</em> + directory. There is a specific script for each of the most popular + database systems. If the script for your particular type of + database system is missing, it should be quite easy to write one, + taking example on the already existing scripts. If you send them + to us, we will gladly include missing scripts in future releases. </p> <p> Modified: logback/trunk/logback-site/src/site/pages/news.html ============================================================================== --- logback/trunk/logback-site/src/site/pages/news.html (original) +++ logback/trunk/logback-site/src/site/pages/news.html Wed Oct 15 00:45:06 2008 @@ -81,7 +81,6 @@ </p> - <p>Fixed issue <a href="http://jira.qos.ch/browse/LBCORE-27">LBCORE-27</a> reported by Peter Royal. SMTPAppender now outputs its presentation footer and @@ -110,6 +109,13 @@ <p>Fixed issue <a href="http://jira.qos.ch/browse/LBGENERAL-24">LBGENERAL-24</a> + reported by Hung Tang. SMTPAppender now supports plain + username/password authentication as well as both the STARTTLS + command and SSL connections. + </p> + + <p>Fixed issue <a + href="http://jira.qos.ch/browse/LBCORE-17">LBCORE-17</a> reported by Thorbjørn Ravn Andersen. Logback now relies on Geronimo JMS API specifications instead of Sun's JMS API specification, the latter requiring manual installation. With @@ -117,7 +123,6 @@ manually install any dependencies. </p> - <p><a href="http://jira.qos.ch/browse/LBCORE-32">LBCORE-32</a> </p>