add mail notification
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 2a5f178..1398e4c 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -584,6 +584,22 @@
 		goto out;
 #endif
 	}
+  else if (!strcmp(args[0], "email_alert")) {
+    global.email_alert = 1;
+    if (*(args[1]) == 0) {
+      Alert("parsing [%s:%d] : email_alert Expects email address as argument.\n", file, linenum);
+      global.email_alert = 0;
+      err_code |= ERR_ALERT;
+      goto out;
+    }
+    if (*(args[2]) != 0) {
+      strncpy(global.email_from,args[2],50);
+    }
+    else {
+      strncpy(global.email_from,"na",50);
+    }
+    strncpy(global.email_to,args[1],50);
+  } 
 	else if (!strcmp(args[0], "daemon")) {
 		global.mode |= MODE_DAEMON;
 	}
diff --git a/src/checks.c b/src/checks.c
index 27a23b2..1cda9d4 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <stdarg.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <netinet/in.h>
@@ -294,6 +295,7 @@
 			     (check->health >= check->rise) ? (s->uweight ? "UP" : "DRAIN") : "DOWN");
 
 		Warning("%s.\n", trash.str);
+		Emaila("%s \n", trash.str);
 		send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
 	}
 }
diff --git a/src/log.c b/src/log.c
index 1a5ad25..0a1b61a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -583,6 +583,40 @@
 	}
 }
 
+
+void Emaila(const char *fmt, ...)
+{
+  va_list argp;
+  char buf[200];
+  char alertcmd[200];
+  int sysreturn;  
+
+  if (global.email_alert) {
+    va_start(argp, fmt);
+    vsnprintf(buf,100,fmt, argp);
+    /*if no from address is set use default */  
+    if (!strcmp(global.email_from,"na")) {
+      snprintf(alertcmd,200,"echo \" %s\" | mail -s \"Loadbalancer layer7 alert\" %s &",buf,global.email_to);
+      sysreturn = system(alertcmd);
+      if (sysreturn == -1) {
+        Warning("There was an error sending the email alert");
+      }
+
+    }
+    else {
+      snprintf(alertcmd,200,"echo \" %s\" | mail -s \"Loadbalancer layer7 alert\" %s -a \"From:<%s>\" &",buf,global.email_to,global.email_from);
+      sysreturn = system(alertcmd);
+      if (sysreturn == -1) {
+        Warning("There was an error sending the email alert");
+      }
+    }
+    vfprintf(stderr, fmt, argp);
+    fflush(stderr);
+    va_end(argp);
+  }
+}
+
+
 /*
  * Displays the message on <out> only if quiet mode is not set.
  */