Index: src/main/php/appenders/LoggerAppenderMail.php
===================================================================
--- src/main/php/appenders/LoggerAppenderMail.php	(revision 1380174)
+++ src/main/php/appenders/LoggerAppenderMail.php	(working copy)
@@ -33,6 +33,7 @@
  *     addresses may be specified by separating them with a comma.
  * - **from** - Email address which will be used in the From field.
  * - **subject** - Subject of the email message.
+ * - **bufferSize** - Output buffer size. Number of messages sent together
  * 
  * @version $Revision$
  * @package log4php
@@ -46,19 +47,37 @@
 	 * Email address to put in From field of the email.
 	 * @var string
 	 */
-	protected $from = null;
+	protected $from;
 
 	/** 
+	 * Mail server port (widnows only).
+	 * @var integer 
+	 */
+	protected $port = 25;
+
+	/** 
+	 * Mail server hostname (windows only).
+	 * @var string   
+	 */
+	protected $smtpHost;
+
+	/** 
 	 * The subject of the email.
 	 * @var string
 	 */
 	protected $subject = 'Log4php Report';
-	
+
 	/**
 	 * One or more comma separated email addresses to which to send the email. 
 	 * @var string
 	 */
 	protected $to = null;
+			
+	/**
+	 * Output buffer size
+	 * @var integer
+	 */
+	protected $bufferSize = NULL;
 
 	/** 
 	 * Indiciates whether this appender should run in dry mode.
@@ -66,42 +85,134 @@
 	 * @var boolean 
 	 */
 	protected $dry = false;
-
+	
 	/** 
 	 * Buffer which holds the email contents before it is sent. 
 	 * @var string  
 	 */
 	protected $body = '';
+		
+	/** 
+	 * Number of messages in buffer
+	 * @var string  
+	 */
+	protected $bufferCounter = NULL;
 	
+	
+	public function activateOptions() {
+		if (empty($this->to)) {
+			$this->warn("Required parameter 'to' not set. Closing appender.");
+			$this->close = true;
+			return;
+		}
+		
+		$sendmail_from = ini_get('sendmail_from');
+		if (empty($this->from) and empty($sendmail_from)) {
+			$this->warn("Required parameter 'from' not set. Closing appender.");
+			$this->close = true;
+			return;
+		}
+		
+		if(!isset($this->bufferSize)) {
+			$this->bufferSize = PHP_INT_MAX;
+		}
+		
+		$this->closed = false;
+	}
+
 	public function append(LoggerLoggingEvent $event) {
+		
 		if($this->layout !== null) {
 			$this->body .= $this->layout->format($event);
 		}
+		
+		if( ++$this->bufferCounter >= $this->bufferSize ) {
+			$this->send();
+		}
+		
+
 	}
 	
+	public function send() {
+		
+		$smtpHost = $this->smtpHost;
+		$prevSmtpHost = ini_get('SMTP');
+		if(!empty($smtpHost)) {
+			ini_set('SMTP', $smtpHost);
+		}
+
+		$smtpPort = $this->port;
+		$prevSmtpPort= ini_get('smtp_port');
+		if($smtpPort > 0 and $smtpPort < 65535) {
+			ini_set('smtp_port', $smtpPort);
+		}
+
+		// On unix only sendmail_path, which is PHP_INI_SYSTEM i.e. not changeable here, is used.
+
+		$addHeader = empty($this->from) ? '' : "From: {$this->from}\r\n";
+
+		if(!$this->dry) {
+			$result = mail($this->to, $this->subject, $this->layout->getHeader() . $this->body . $this->layout->getFooter(), $addHeader);
+		} else {
+			echo "DRY MODE OF MAIL APP.: Send mail to: ".$this->to." with content: ".$this->body;
+		}
+			
+		ini_set('SMTP', $prevSmtpHost);
+		ini_set('smtp_port', $prevSmtpPort);
+
+		$this->bufferCounter = 0;
+		$this->body = '';
+	}
+	
+	
 	public function close() {
 		if($this->closed != true) {
-			$from = $this->from;
-			$to = $this->to;
-	
-			if(!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) {
-				$subject = $this->subject;
-				if(!$this->dry) {
-					mail(
-						$to, $subject, 
-						$this->layout->getHeader() . $this->body . $this->layout->getFooter(),
-						"From: {$from}\r\n");
-				} else {
-				    echo "DRY MODE OF MAIL APP.: Send mail to: ".$to." with content: ".$this->body;
-				}
+			
+			if( $this->bufferCounter > 0 ) {
+				$this->send();
 			}
+			
 			$this->closed = true;
 		}
+		
+		parent::close();
 	}
 	
+	
+	
+	/** Sets the 'from' parameter. */
+	public function setFrom($from) {
+		$this->setString('from', $from);
+	}
+	
+	/** Returns the 'from' parameter. */
+	public function getFrom() {
+		return $this->from;
+	}
+	
+	/** Sets the 'port' parameter. */
+	public function setPort($port) {
+		$this->setPositiveInteger('port', $port);
+	}
+	
+	/** Returns the 'port' parameter. */
+	public function getPort() {
+		return $this->port;
+	}
+	
+	/** Sets the 'smtpHost' parameter. */
+	public function setSmtpHost($smtpHost) {
+		$this->setString('smtpHost', $smtpHost);
+	}
+	
+	/** Returns the 'smtpHost' parameter. */
+	public function getSmtpHost() {
+		return $this->smtpHost;
+	}
+	
 	/** Sets the 'subject' parameter. */
 	public function setSubject($subject) {
-		$this->setString('subject', $subject);
+		$this->setString('subject',  $subject);
 	}
 	
 	/** Returns the 'subject' parameter. */
@@ -111,24 +222,24 @@
 	
 	/** Sets the 'to' parameter. */
 	public function setTo($to) {
-		$this->setString('to', $to);
+		$this->setString('to',  $to);
 	}
 	
 	/** Returns the 'to' parameter. */
 	public function getTo() {
 		return $this->to;
 	}
-
-	/** Sets the 'from' parameter. */
-	public function setFrom($from) {
-		$this->setString('from', $from);
+	
+	/** Sets the 'bufferSize' parameter. */
+	public function setBufferSize($bufferSize) {
+		$this->setInteger('bufferSize', $bufferSize);
 	}
 	
-	/** Returns the 'from' parameter. */
-	public function getFrom() {
-		return $this->from;
+	/** Returns the 'bufferSize' parameter. */
+	public function getBufferSize() {
+		return $this->bufferSize;
 	}
-
+	
 	/** Enables or disables dry mode. */
 	public function setDry($dry) {
 		$this->setBoolean('dry', $dry);
Index: src/main/php/appenders/LoggerAppenderMailEvent.php
===================================================================
--- src/main/php/appenders/LoggerAppenderMailEvent.php	(revision 1380174)
+++ src/main/php/appenders/LoggerAppenderMailEvent.php	(working copy)
@@ -37,6 +37,7 @@
  * @version $Revision$
  * @package log4php
  * @subpackage appenders
+ * @deprecated
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/mail-event.html Appender documentation
  */
