logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r438983 - /logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SMTPAppender.java
Date Thu, 31 Aug 2006 16:50:31 GMT
Author: carnold
Date: Thu Aug 31 09:50:31 2006
New Revision: 438983

URL: http://svn.apache.org/viewvc?rev=438983&view=rev
Log:
Bug 18246: Add cc and bcc addresses to SMTPAppender

Modified:
    logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SMTPAppender.java

Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SMTPAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SMTPAppender.java?rev=438983&r1=438982&r2=438983&view=diff
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SMTPAppender.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SMTPAppender.java Thu
Aug 31 09:50:31 2006
@@ -53,6 +53,14 @@
    @since 1.0 */
 public class SMTPAppender extends AppenderSkeleton {
   private String to;
+  /**
+   * Comma separated list of cc recipients.
+   */
+  private String cc;  
+  /**
+   * Comma separated list of bcc recipients.
+   */
+  private String bcc;  
   private String from;
   private String subject;
   private String smtpHost;
@@ -100,18 +108,41 @@
     msg = new MimeMessage(session);
 
      try {
-       if (from != null)
-	 msg.setFrom(getAddress(from));
-       else
-	 msg.setFrom();
-
-       msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
-       if(subject != null)
-	 msg.setSubject(subject);
+        addressMessage(msg);
+        if(subject != null) {
+	       msg.setSubject(subject);
+	    }
      } catch(MessagingException e) {
        LogLog.error("Could not activate SMTPAppender options.", e );
      }
   }
+  
+  /**
+   *   Address message.
+   *   @param msg message, may not be null.
+   *   @throws MessagingException thrown if error addressing message. 
+   */
+  protected void addressMessage(final Message msg) throws MessagingException {
+       if (from != null) {
+	 		msg.setFrom(getAddress(from));
+       } else {
+	 		msg.setFrom();
+	   }
+
+       if (to != null && to.length() > 0) {
+             msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
+       }
+
+      //Add CC receipients if defined.
+	  if (cc != null && cc.length() > 0) {
+		msg.setRecipients(Message.RecipientType.CC, parseAddress(cc));
+	  }
+
+      //Add BCC receipients if defined.
+	  if (bcc != null && bcc.length() > 0) {
+		msg.setRecipients(Message.RecipientType.BCC, parseAddress(bcc));
+	  }
+  }
 
   /**
      Perform SMTPAppender specific appending actions, mainly adding
@@ -384,6 +415,40 @@
   boolean getLocationInfo() {
     return locationInfo;
   }
+  
+   /**
+      Set the cc recipient addresses.
+      @param addresses recipient addresses as comma separated string, may be null.
+    */
+   public void setCc(final String addresses) {
+     this.cc = addresses;
+   }
+
+   /**
+      Get the cc recipient addresses.
+      @return recipient addresses as comma separated string, may be null.
+    */
+    public String getCc() {
+     return cc;
+    }
+
+   /**
+      Set the bcc recipient addresses.
+      @param addresses recipient addresses as comma separated string, may be null.
+    */
+   public void setBcc(final String addresses) {
+     this.bcc = addresses;
+   }
+
+   /**
+      Get the bcc recipient addresses.
+      @return recipient addresses as comma separated string, may be null.
+    */
+    public String getBcc() {
+     return bcc;
+    }
+
+  
 }
 
 class DefaultEvaluator implements TriggeringEventEvaluator {



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message