diff --git a/testsuite/tools/pom.xml b/testsuite/tools/pom.xml
index e6e0f79002..3d3d2c3256 100755
--- a/testsuite/tools/pom.xml
+++ b/testsuite/tools/pom.xml
@@ -15,6 +15,19 @@
+
+
+ com.icegreen
+ greenmail
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+
+
org.keycloak
keycloak-core
diff --git a/testsuite/tools/src/main/java/org/keycloak/test/tools/DestroyListener.java b/testsuite/tools/src/main/java/org/keycloak/test/tools/DestroyListener.java
new file mode 100644
index 0000000000..99807dcdbf
--- /dev/null
+++ b/testsuite/tools/src/main/java/org/keycloak/test/tools/DestroyListener.java
@@ -0,0 +1,21 @@
+package org.keycloak.test.tools;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ * @author Stian Thorgersen
+ */
+public class DestroyListener implements ServletContextListener {
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ if (KeycloakTestApplication.mail != null) {
+ KeycloakTestApplication.mail.stop();
+ }
+ }
+}
diff --git a/testsuite/tools/src/main/java/org/keycloak/test/tools/KeycloakTestApplication.java b/testsuite/tools/src/main/java/org/keycloak/test/tools/KeycloakTestApplication.java
index 52e7811007..7184978d64 100644
--- a/testsuite/tools/src/main/java/org/keycloak/test/tools/KeycloakTestApplication.java
+++ b/testsuite/tools/src/main/java/org/keycloak/test/tools/KeycloakTestApplication.java
@@ -5,6 +5,8 @@ import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.services.resources.KeycloakApplication;
import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import java.util.HashSet;
@@ -19,6 +21,8 @@ public class KeycloakTestApplication extends Application {
protected Set> classes = new HashSet>();
protected Set