You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2006/08/31 18:55:02 UTC

svn commit: r438984 - /logging/log4j/trunk/src/java/org/apache/log4j/net/SMTPAppender.java

Author: carnold
Date: Thu Aug 31 09:55:01 2006
New Revision: 438984

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

Modified:
    logging/log4j/trunk/src/java/org/apache/log4j/net/SMTPAppender.java

Modified: logging/log4j/trunk/src/java/org/apache/log4j/net/SMTPAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/net/SMTPAppender.java?rev=438984&r1=438983&r2=438984&view=diff
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/net/SMTPAppender.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/net/SMTPAppender.java Thu Aug 31 09:55:01 2006
@@ -77,6 +77,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 subjectStr = "";
   private String smtpHost;
@@ -121,13 +129,7 @@
     msg = new MimeMessage(session);
 
     try {
-      if (from != null) {
-        msg.setFrom(getAddress(from));
-      } else {
-        msg.setFrom();
-      }
-
-      msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
+       addressMessage(msg);
     } catch (MessagingException e) {
       errorCount++;
       getLogger().error("Could not activate SMTPAppender options.", e);
@@ -158,6 +160,34 @@
       super.activateOptions();
     }
   }
+  
+  /**
+   *   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
@@ -459,6 +489,38 @@
     public String getCharset() {
         return charset;
      }
+
+   /**
+      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;
+    }
 
 }
 



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