--- Downloads/logging-log4j-1.2.9/src/java/org/apache/log4j/net/SMTPAppender.java Mon Nov 1 20:21:14 2004
+++ Softdev/lusightDev/lusight/source/com/lusight/log4j/SMTPAppender.java Tue Apr 26 09:13:45 2005
@@ -19,6 +19,8 @@
import java.util.Date;
import javax.mail.Session;
+import javax.mail.Authenticator;
+import javax.mail.PasswordAuthentication;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.MessagingException;
@@ -47,8 +49,11 @@
private String from;
private String subject;
private String smtpHost;
+ private String smtpUsername;
+ private String smtpPassword;
private int bufferSize = 512;
private boolean locationInfo = false;
+ private boolean smtpDebug = false;
protected CyclicBuffer cb = new CyclicBuffer(bufferSize);
protected Message msg;
@@ -85,8 +90,23 @@
if (smtpHost != null)
props.put("mail.smtp.host", smtpHost);
+ Authenticator authenticator = null;
+
+ if(smtpPassword != null && smtpUsername != null) {
+ // Setup mail server authentication
+ props.put("mail.smtp.auth", "true");
+
+ authenticator = new Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(smtpUsername, smtpPassword);
+ }
+ };
+ }
+
+ // Get session
+ Session session = Session.getDefaultInstance(props,authenticator);
+ session.setDebug(smtpDebug);
- Session session = Session.getInstance(props, null);
//session.setDebug(true);
msg = new MimeMessage(session);
@@ -242,7 +262,30 @@
}
}
+ /**
+ * The SmtpPassword option takes a string value which should be the password required to authenticate against
+ * the mail server
+ */
+ public void setSMTPPassword(String smtpPassword) {
+ this.smtpPassword = smtpPassword;
+ }
+ /**
+ * The SmtpUsername option takes a string value which should be the username required to authenticate against
+ * the mail server
+ */
+ public void setSMTPUsername(String smtpUsername) {
+ this.smtpUsername = smtpUsername;
+ }
+
+ /**
+ * Setting the SmtpDebug option to true will cause the mail session to log its server interaction to stdout.
+ * This can be useful when debuging the appender but should not be used during production because username and
+ * password information is included in the output.
+ */
+ public void setSMTPDebug(boolean debug) {
+ this.smtpDebug = debug;
+ }
/**
Returns value of the EvaluatorClass option.