james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [25/44] james-project git commit: JAMES-2267 MessageSender should be a test rule
Date Fri, 05 Jan 2018 02:56:44 GMT
JAMES-2267 MessageSender should be a test rule


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2da49b99
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2da49b99
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2da49b99

Branch: refs/heads/improve-mailet-testing-experience-v1
Commit: 2da49b99e3fe38c878ac4c6d2bcf0a17a6d2bb41
Parents: 9e639ad
Author: benwa <btellier@linagora.com>
Authored: Tue Dec 19 16:21:13 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 09:33:19 2018 +0700

----------------------------------------------------------------------
 .../james/mailets/AddDeliveredToHeaderTest.java |  40 ++--
 .../james/mailets/BounceIntegrationTest.java    | 107 +++++------
 .../mailets/CommonMailetConfigurationTest.java  |  32 ++--
 .../GatewayRemoteDeliveryIntegrationTest.java   |  92 +++++----
 .../RecipientRewriteTableIntegrationTest.java   | 103 +++++-----
 .../org/apache/james/mailets/SieveDelivery.java |  33 ++--
 .../james/mailets/SmtpAuthIntegrationTest.java  |  48 +++--
 .../james/mailets/configuration/Constants.java  |   2 +
 .../crypto/SMIMEDecryptIntegrationTest.java     |  70 ++++---
 .../james/smtp/SmtpAuthorizedAddressesTest.java |  53 +++---
 .../james/smtp/SmtpBracketEnforcementTest.java  |  42 ++---
 .../smtp/SmtpIdentityVerificationTest.java      |  31 ++-
 .../james/smtp/SmtpSizeLimitationTest.java      |  20 +-
 .../mailets/AmqpForwardAttachmentTest.java      |  17 +-
 .../transport/mailets/ContactExtractorTest.java |  31 +--
 .../mailets/ICSAttachmentWorkflowTest.java      | 187 +++++++++----------
 .../transport/mailets/StripAttachmentTest.java  |  19 +-
 .../apache/james/utils/SMTPMessageSender.java   |  34 +++-
 18 files changed, 462 insertions(+), 499 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java
index bd47efb..36f95da 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java
@@ -21,15 +21,15 @@ package org.apache.james.mailets;
 
 import static com.jayway.awaitility.Duration.ONE_MINUTE;
 import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.FROM;
 import static org.apache.james.mailets.configuration.Constants.IMAP_PORT;
 import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
 import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
 import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
 import static org.apache.james.mailets.configuration.Constants.calmlyAwait;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.transport.mailets.AddDeliveredToHeader;
 import org.apache.james.utils.DataProbeImpl;
@@ -46,12 +46,18 @@ public class AddDeliveredToHeaderTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
     @Before
     public void setup() throws Exception {
         jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
+
+        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DEFAULT_DOMAIN);
+        dataProbe.addUser(RECIPIENT, PASSWORD);
     }
 
     @After
@@ -61,27 +67,15 @@ public class AddDeliveredToHeaderTest {
 
     @Test
     public void receivedMessagesShouldContainDeliveredToHeaders() throws Exception {
-        String from = "user@" + DEFAULT_DOMAIN;
-        String recipient = "user2@" + DEFAULT_DOMAIN;
-
-        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
-        dataProbe.addDomain(DEFAULT_DOMAIN);
-        dataProbe.addUser(from, PASSWORD);
-        dataProbe.addUser(recipient, PASSWORD);
-
-        jamesServer.getProbe(MailboxProbeImpl.class)
-            .createMailbox(MailboxConstants.USER_NAMESPACE, recipient, "INBOX");
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(from, recipient)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(recipient, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            assertThat(imapMessageReader.readFirstMessageHeaders())
-                .contains(AddDeliveredToHeader.DELIVERED_TO + ": " + recipient);
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        assertThat(imapMessageReader.readFirstMessageHeaders())
+            .contains(AddDeliveredToHeader.DELIVERED_TO + ": " + RECIPIENT);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java
index b23082f..6d8c1cf 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java
@@ -24,6 +24,7 @@ import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
 import static org.apache.james.mailets.configuration.Constants.IMAP_PORT;
 import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
 import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
 import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
 import static org.apache.james.mailets.configuration.Constants.calmlyAwait;
 
@@ -55,12 +56,13 @@ import org.junit.rules.TemporaryFolder;
 public class BounceIntegrationTest {
     public static final String POSTMASTER = "postmaster@" + DEFAULT_DOMAIN;
     public static final String BOUNCE_RECEIVER = "bounce.receiver@" + DEFAULT_DOMAIN;
-    private static final String RECIPIENT = "to@" + DEFAULT_DOMAIN;
 
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
     private DataProbe dataProbe;
@@ -80,20 +82,19 @@ public class BounceIntegrationTest {
                 .mailet(DSNBounce.class)
                 .addProperty("passThrough", "false")))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(BOUNCE_RECEIVER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(BOUNCE_RECEIVER, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(BOUNCE_RECEIVER, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(BOUNCE_RECEIVER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(BOUNCE_RECEIVER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -106,20 +107,19 @@ public class BounceIntegrationTest {
                 .mailet(Bounce.class)
                 .addProperty("passThrough", "false")))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(BOUNCE_RECEIVER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(BOUNCE_RECEIVER, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(BOUNCE_RECEIVER, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(BOUNCE_RECEIVER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(BOUNCE_RECEIVER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -132,20 +132,19 @@ public class BounceIntegrationTest {
                 .addProperty("forwardTo", BOUNCE_RECEIVER)
                 .addProperty("passThrough", "false")))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(BOUNCE_RECEIVER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(BOUNCE_RECEIVER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(BOUNCE_RECEIVER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -159,20 +158,19 @@ public class BounceIntegrationTest {
                     .addProperty("recipients", BOUNCE_RECEIVER)
                     .addProperty("passThrough", "false")))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(BOUNCE_RECEIVER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(BOUNCE_RECEIVER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(BOUNCE_RECEIVER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -186,20 +184,19 @@ public class BounceIntegrationTest {
                     .addProperty("recipients", BOUNCE_RECEIVER)
                     .addProperty("passThrough", "false")))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(BOUNCE_RECEIVER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(BOUNCE_RECEIVER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(BOUNCE_RECEIVER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -212,20 +209,19 @@ public class BounceIntegrationTest {
                     .mailet(NotifySender.class)
                     .addProperty("passThrough", "false")))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(BOUNCE_RECEIVER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(BOUNCE_RECEIVER, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(BOUNCE_RECEIVER, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(BOUNCE_RECEIVER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(BOUNCE_RECEIVER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -244,14 +240,13 @@ public class BounceIntegrationTest {
         dataProbe.addUser(RECIPIENT, PASSWORD);
         dataProbe.addUser(POSTMASTER, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage("any@" + DEFAULT_DOMAIN, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(POSTMASTER, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(POSTMASTER, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     private MailetContainer generateMailetContainerConfiguration(MailetConfiguration.Builder redirectionMailetConfiguration) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java
index 2b61ade..7f13bc8 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java
@@ -21,14 +21,14 @@ package org.apache.james.mailets;
 
 import static com.jayway.awaitility.Duration.ONE_MINUTE;
 import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.FROM;
 import static org.apache.james.mailets.configuration.Constants.IMAP_PORT;
 import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
 import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
 import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
 import static org.apache.james.mailets.configuration.Constants.calmlyAwait;
 
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.IMAPMessageReader;
@@ -44,12 +44,17 @@ public class CommonMailetConfigurationTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
     @Before
     public void setup() throws Exception {
         jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
+        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DEFAULT_DOMAIN);
+        dataProbe.addUser(RECIPIENT, PASSWORD);
     }
 
     @After
@@ -63,22 +68,13 @@ public class CommonMailetConfigurationTest {
 
     @Test
     public void simpleMailShouldBeSent() throws Exception {
-        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
-        dataProbe.addDomain(DEFAULT_DOMAIN);
-        String from = "user@" + DEFAULT_DOMAIN;
-        dataProbe.addUser(from, PASSWORD);
-        String recipient = "user2@" + DEFAULT_DOMAIN;
-        dataProbe.addUser(recipient, PASSWORD);
-        jamesServer.getProbe(MailboxProbeImpl.class).createMailbox(MailboxConstants.USER_NAMESPACE, recipient, "INBOX");
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(from, recipient)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(recipient, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
index 75dc866..34a44e4 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
@@ -78,6 +78,8 @@ public class GatewayRemoteDeliveryIntegrationTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private final TemporaryFolder smtpFolder = new TemporaryFolder();
     private final SwarmGenericContainer fakeSmtp = new SwarmGenericContainer(Images.FAKE_SMTP)
@@ -119,16 +121,15 @@ public class GatewayRemoteDeliveryIntegrationTest {
             .withBase(SMTP_ONLY_MODULE)
             .withMailetContainer(generateMailetContainerConfiguration(gatewayProperty))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -139,16 +140,15 @@ public class GatewayRemoteDeliveryIntegrationTest {
             .withBase(SMTP_ONLY_MODULE)
             .withMailetContainer(generateMailetContainerConfiguration(gatewayProperty))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -159,16 +159,15 @@ public class GatewayRemoteDeliveryIntegrationTest {
             .withBase(SMTP_ONLY_MODULE)
             .withMailetContainer(generateMailetContainerConfiguration(gatewayProperty))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -184,11 +183,10 @@ public class GatewayRemoteDeliveryIntegrationTest {
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -208,16 +206,15 @@ public class GatewayRemoteDeliveryIntegrationTest {
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            Thread.sleep(TimeUnit.SECONDS.toMillis(5));
-            when()
-                .get("/api/email")
-            .then()
-                .statusCode(200)
-                .body("", hasSize(0));
-        }
+        Thread.sleep(TimeUnit.SECONDS.toMillis(5));
+        when()
+            .get("/api/email")
+        .then()
+            .statusCode(200)
+            .body("", hasSize(0));
     }
     @Test
     public void remoteDeliveryShouldBounceUponFailure() throws Exception {
@@ -236,19 +233,18 @@ public class GatewayRemoteDeliveryIntegrationTest {
                 .addProcessor(relayAndLocalDeliveryTransport(gatewayProperty))
                 .addProcessor(CommonProcessors.bounces()))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(FROM, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -285,19 +281,18 @@ public class GatewayRemoteDeliveryIntegrationTest {
                         .addProperty("gateway", gatewayProperty)))
                 .addProcessor(CommonProcessors.bounces()))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(FROM, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -316,16 +311,15 @@ public class GatewayRemoteDeliveryIntegrationTest {
                 .addProcessor(directResolutionTransport())
                 .addProcessor(CommonProcessors.bounces()))
             .build(temporaryFolder);
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
 
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT);
 
-            calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
     }
 
     private boolean messageIsReceivedByTheSmtpServer() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java
index decf799..ea0773e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java
@@ -54,6 +54,8 @@ public class RecipientRewriteTableIntegrationTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
     private DataProbe dataProbe;
@@ -76,32 +78,29 @@ public class RecipientRewriteTableIntegrationTest {
     @Test
     public void rrtServiceShouldDeliverEmailToMappingRecipients() throws Exception {
         dataProbe.addUser(FROM, PASSWORD);
-
         createUserInbox(ANY_AT_JAMES);
         createUserInbox(OTHER_AT_JAMES);
 
         dataProbe.addAddressMapping("touser", DEFAULT_DOMAIN, ANY_AT_JAMES);
         dataProbe.addAddressMapping("touser", DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(ANY_AT_JAMES, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(OTHER_AT_JAMES, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(ANY_AT_JAMES, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(OTHER_AT_JAMES, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
     public void rrtServiceShouldNotDeliverEmailToRecipientWhenHaveMappingRecipients() throws Exception {
         dataProbe.addUser(FROM, PASSWORD);
-
         createUserInbox(RECIPIENT);
         createUserInbox(ANY_AT_JAMES);
         createUserInbox(OTHER_AT_JAMES);
@@ -109,79 +108,71 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addAddressMapping("touser", DEFAULT_DOMAIN, ANY_AT_JAMES);
         dataProbe.addAddressMapping("touser", DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX);
-            calmlyAwait.atMost(ONE_MINUTE).until(imapMessageReader::userDoesNotReceiveMessage);
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX);
+        calmlyAwait.atMost(ONE_MINUTE).until(imapMessageReader::userDoesNotReceiveMessage);
     }
 
     @Test
     public void rrtServiceShouldDeliverEmailToRecipientOnLocalWhenMappingContainsNonDomain() throws Exception {
         String nonDomainUser = "nondomain";
         String localUser = nonDomainUser + "@" + dataProbe.getDefaultDomain();
-
         dataProbe.addUser(FROM, PASSWORD);
-
         createUserInbox(localUser);
         createUserInbox(OTHER_AT_JAMES);
 
         dataProbe.addAddressMapping("touser", DEFAULT_DOMAIN, nonDomainUser);
         dataProbe.addAddressMapping("touser", DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, RECIPIENT)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(localUser, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(OTHER_AT_JAMES, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(localUser, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(OTHER_AT_JAMES, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
     public void messageShouldRedirectToTheSameUserWhenDomainMapping() throws Exception {
         dataProbe.addDomainAliasMapping(DEFAULT_DOMAIN, JAMES_ANOTHER_DOMAIN);
-
         createUserInbox(ANY_AT_JAMES);
         createUserInbox(ANY_AT_ANOTHER_DOMAIN);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, ANY_AT_JAMES)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, ANY_AT_JAMES)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(ANY_AT_ANOTHER_DOMAIN, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(ANY_AT_ANOTHER_DOMAIN, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
     public void messageShouldNotSendToRecipientWhenDomainMapping() throws Exception {
         dataProbe.addDomainAliasMapping(DEFAULT_DOMAIN, JAMES_ANOTHER_DOMAIN);
-
         createUserInbox(ANY_AT_JAMES);
         createUserInbox(ANY_AT_ANOTHER_DOMAIN);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(FROM, ANY_AT_JAMES)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, ANY_AT_JAMES)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(ANY_AT_JAMES, PASSWORD)
-                .select(IMAPMessageReader.INBOX);
-            calmlyAwait.atMost(ONE_MINUTE).until(imapMessageReader::userDoesNotReceiveMessage);
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(ANY_AT_JAMES, PASSWORD)
+            .select(IMAPMessageReader.INBOX);
+        calmlyAwait.atMost(ONE_MINUTE).until(imapMessageReader::userDoesNotReceiveMessage);
     }
 
     private void createUserInbox(String username) throws Exception {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java
index 3d5fc03..7a2d064 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java
@@ -21,9 +21,11 @@ package org.apache.james.mailets;
 
 import static com.jayway.awaitility.Duration.ONE_MINUTE;
 import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.FROM;
 import static org.apache.james.mailets.configuration.Constants.IMAP_PORT;
 import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
 import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
 import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
 import static org.apache.james.mailets.configuration.Constants.calmlyAwait;
 
@@ -46,29 +48,25 @@ public class SieveDelivery {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
     private String targetedMailbox;
-    private String recipient;
-    private String from;
 
     @Before
     public void setup() throws Exception {
         jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
 
-
-        from = "user@" + DEFAULT_DOMAIN;
-        recipient = "user2@" + DEFAULT_DOMAIN;
         targetedMailbox = "INBOX.any";
 
         DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
-        dataProbe.addUser(from, PASSWORD);
-        dataProbe.addUser(recipient, PASSWORD);
+        dataProbe.addUser(FROM, PASSWORD);
+        dataProbe.addUser(RECIPIENT, PASSWORD);
 
         MailboxProbe mailboxProbe = jamesServer.getProbe(MailboxProbeImpl.class);
-        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, recipient, "INBOX");
-        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, recipient, targetedMailbox);
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, RECIPIENT, targetedMailbox);
     }
 
     @After
@@ -78,18 +76,17 @@ public class SieveDelivery {
 
     @Test
     public void simpleMailShouldBeSent() throws Exception {
-        jamesServer.getProbe(SieveProbeImpl.class).addActiveSieveScript(recipient, "myscript.sieve", "require \"fileinto\";\n" +
+        jamesServer.getProbe(SieveProbeImpl.class).addActiveSieveScript(RECIPIENT, "myscript.sieve", "require \"fileinto\";\n" +
             "\n" +
             "fileinto \"" + targetedMailbox + "\";");
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN);) {
-            messageSender.sendMessage(from, recipient)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(recipient, PASSWORD)
-                .select(targetedMailbox)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(targetedMailbox)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
index 68385ae..624edae 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
@@ -57,8 +57,11 @@ public class SmtpAuthIntegrationTest {
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
+    private MailRepositoryProbeImpl repositoryProbe;
 
     @Before
     public void setup() throws Exception {
@@ -85,6 +88,7 @@ public class SmtpAuthIntegrationTest {
             .withBase(MemoryJamesServerMain.SMTP_AND_IMAP_MODULE)
             .withMailetContainer(mailetContainer)
             .build(temporaryFolder);
+        repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
         DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
         dataProbe.addUser(FROM, PASSWORD);
@@ -117,36 +121,30 @@ public class SmtpAuthIntegrationTest {
 
     @Test
     public void authenticatedSmtpSessionsShouldBeDelivered() throws Exception {
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, FROM, PASSWORD)) {
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(FROM, PASSWORD)
+            .sendMessage(FROM, FROM)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+    }
 
-            messageSender.sendMessage(FROM, FROM)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+    @Test
+    public void nonAuthenticatedSmtpSessionsShouldNotBeDelivered() throws Exception {
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, FROM)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
+        calmlyAwait.atMost(ONE_MINUTE).until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1);
+        assertThat(
             imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
                 .login(FROM, PASSWORD)
                 .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
-    }
-
-    @Test
-    public void nonAuthenticatedSmtpSessionsShouldNotBeDelivered() throws Exception {
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-
-            messageSender.sendMessage(FROM, FROM)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            MailRepositoryProbeImpl repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
-            calmlyAwait.atMost(ONE_MINUTE).until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1);
-            assertThat(
-                imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                    .login(FROM, PASSWORD)
-                    .select(IMAPMessageReader.INBOX)
-                    .hasAMessage())
-                .isFalse();
-        }
+                .hasAMessage())
+            .isFalse();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
index 0d2bd72..7c16fbb 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
@@ -37,4 +37,6 @@ public class Constants {
     public static final int IMAP_PORT = 1143;
     public static final int SMTP_PORT = 1025;
     public static final String PASSWORD = "secret";
+    public static final String FROM = "user@" + DEFAULT_DOMAIN;
+    public static final String RECIPIENT = "user2@" + DEFAULT_DOMAIN;
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
index 16e9ccc..d02e901 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
@@ -62,6 +62,8 @@ public class SMIMEDecryptIntegrationTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
@@ -105,53 +107,49 @@ public class SMIMEDecryptIntegrationTest {
 
     @Test
     public void cryptedMessageShouldBeDecryptedWhenCertificateMatches() throws Exception {
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_SECURE_PORT, DEFAULT_DOMAIN, FROM, PASSWORD)) {
-
-            messageSender.sendMessageWithHeaders(FROM, FROM,
+        messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
+            .authenticate(FROM, PASSWORD)
+            .sendMessageWithHeaders(FROM, FROM,
                 IOUtils.toString(ClassLoader.getSystemResourceAsStream("eml/crypted.eml"), StandardCharsets.US_ASCII))
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(FROM, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            assertThat(imapMessageReader.readFirstMessage()).containsSequence("Crypted content");
-        }
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        assertThat(imapMessageReader.readFirstMessage()).containsSequence("Crypted content");
     }
 
     @Test
     public void cryptedMessageWithAttachmentShouldBeDecryptedWhenCertificateMatches() throws Exception {
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_SECURE_PORT, DEFAULT_DOMAIN, FROM, PASSWORD)) {
-            messageSender.sendMessageWithHeaders(FROM, FROM,
+        messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
+            .authenticate(FROM, PASSWORD)
+            .sendMessageWithHeaders(FROM, FROM,
                 IOUtils.toString(ClassLoader.getSystemResourceAsStream("eml/crypted_with_attachment.eml"), StandardCharsets.US_ASCII))
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(FROM, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            assertThat(imapMessageReader.readFirstMessage())
-                .containsSequence("Crypted Content with attachment");
-        }
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        assertThat(imapMessageReader.readFirstMessage())
+            .containsSequence("Crypted Content with attachment");
     }
 
     @Test
     public void cryptedMessageShouldNotBeDecryptedWhenCertificateDoesntMatch() throws Exception {
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_SECURE_PORT, DEFAULT_DOMAIN, FROM, PASSWORD)) {
-            messageSender.sendMessageWithHeaders(FROM, FROM,
+        messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
+            .authenticate(FROM, PASSWORD)
+            .sendMessageWithHeaders(FROM, FROM,
                 IOUtils.toString(ClassLoader.getSystemResourceAsStream("eml/bad_crypted.eml"), StandardCharsets.US_ASCII))
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(FROM, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            assertThat(imapMessageReader.readFirstMessage())
-                .containsSequence("MIAGCSqGSIb3DQEHA6CAMIACAQAxggKpMIICpQIBADCBjDCBhjELMAkGA1UE");
-        }
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        assertThat(imapMessageReader.readFirstMessage())
+            .containsSequence("MIAGCSqGSIb3DQEHA6CAMIACAQAxggKpMIICpQIBADCBjDCBhjELMAkGA1UE");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
index 489ee06..2bc721b 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
@@ -78,6 +78,8 @@ public class SmtpAuthorizedAddressesTest {
     public RuleChain chain = RuleChain.outerRule(smtpFolder).around(fakeSmtp);
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -153,15 +155,12 @@ public class SmtpAuthorizedAddressesTest {
             .requireAuthentication()
             .withAutorizedAddresses("127.0.0.0/8"));
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-
-            messageSender.sendMessage(FROM, TO)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, TO)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            calmlyAwait.atMost(ONE_MINUTE)
-                .until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE)
+            .until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -170,12 +169,10 @@ public class SmtpAuthorizedAddressesTest {
             .requireAuthentication()
             .withAutorizedAddresses("172.0.0.0/8"));
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, TO);
 
-            messageSender.sendMessage(FROM, TO);
-            calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
     }
 
     @Test
@@ -184,15 +181,12 @@ public class SmtpAuthorizedAddressesTest {
             .requireAuthentication()
             .withAutorizedAddresses("172.0.0.0/8"));
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, FROM, PASSWORD)) {
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(FROM, PASSWORD)
+            .sendMessage(FROM, TO)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            messageSender.sendMessage(FROM, TO)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            calmlyAwait.atMost(ONE_MINUTE)
-                .until(this::messageIsReceivedByTheSmtpServer);
-        }
+        calmlyAwait.atMost(ONE_MINUTE).until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -201,17 +195,14 @@ public class SmtpAuthorizedAddressesTest {
             .requireAuthentication()
             .withAutorizedAddresses("172.0.0.0/8"));
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(TO, FROM)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            messageSender.sendMessage(TO, FROM)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(FROM, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     private boolean messageIsReceivedByTheSmtpServer() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpBracketEnforcementTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpBracketEnforcementTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpBracketEnforcementTest.java
index 0dc6295..14f9505 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpBracketEnforcementTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpBracketEnforcementTest.java
@@ -50,6 +50,8 @@ public class SmtpBracketEnforcementTest {
 
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
@@ -97,12 +99,10 @@ public class SmtpBracketEnforcementTest {
         createJamesServer(SmtpConfiguration.builder()
             .doNotRequireBracketEnforcement());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessage(USER, USER)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD)
+            .sendMessage(USER, USER)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -110,12 +110,10 @@ public class SmtpBracketEnforcementTest {
         createJamesServer(SmtpConfiguration.builder()
             .doNotRequireBracketEnforcement());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessageNoBracket(USER, USER)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD)
+            .sendMessageNoBracket(USER, USER)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -123,12 +121,10 @@ public class SmtpBracketEnforcementTest {
         createJamesServer(SmtpConfiguration.builder()
             .requireBracketEnforcement());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessage(USER, USER)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD)
+            .sendMessage(USER, USER)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -136,11 +132,9 @@ public class SmtpBracketEnforcementTest {
         createJamesServer(SmtpConfiguration.builder()
             .requireBracketEnforcement());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessageNoBracket(USER, USER);
-            calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD)
+            .sendMessageNoBracket(USER, USER);
+        calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpIdentityVerificationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpIdentityVerificationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpIdentityVerificationTest.java
index f56a476..1217df5 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpIdentityVerificationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpIdentityVerificationTest.java
@@ -53,6 +53,8 @@ public class SmtpIdentityVerificationTest {
 
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
@@ -98,12 +100,9 @@ public class SmtpIdentityVerificationTest {
             .requireAuthentication()
             .verifyIdentity());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessage(USER, USER)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD).sendMessage(USER, USER)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -112,12 +111,10 @@ public class SmtpIdentityVerificationTest {
             .requireAuthentication()
             .doNotVerifyIdentity());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, ATTACKER, ATTACKER_PASSWORD)) {
-
-            messageSender.sendMessage(USER, USER)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(ATTACKER, ATTACKER_PASSWORD)
+            .sendMessage(USER, USER)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
     }
 
     @Test
@@ -126,12 +123,10 @@ public class SmtpIdentityVerificationTest {
             .requireAuthentication()
             .verifyIdentity());
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, ATTACKER, ATTACKER_PASSWORD)) {
-
-            messageSender.sendMessage(USER, USER);
-            calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(ATTACKER, ATTACKER_PASSWORD)
+            .sendMessage(USER, USER);
+        calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpSizeLimitationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpSizeLimitationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpSizeLimitationTest.java
index 0716d4e..f2bb893 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpSizeLimitationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpSizeLimitationTest.java
@@ -52,6 +52,8 @@ public class SmtpSizeLimitationTest {
 
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
@@ -100,12 +102,10 @@ public class SmtpSizeLimitationTest {
             .doNotVerifyIdentity()
             .withMaxMessageSizeInKb(10));
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessageWithHeaders(USER, USER, Strings.repeat("Long message", 1024));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD)
+            .sendMessageWithHeaders(USER, USER, Strings.repeat("Long message", 1024));
             calmlyAwait.atMost(ONE_MINUTE).until(messageSender::messageSendingFailed);
-        }
     }
 
     @Test
@@ -114,11 +114,9 @@ public class SmtpSizeLimitationTest {
             .doNotVerifyIdentity()
             .withMaxMessageSizeInKb(10));
 
-        try (SMTPMessageSender messageSender =
-                 SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN, USER, PASSWORD)) {
-
-            messageSender.sendMessageWithHeaders(USER, USER,"Short message")
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(USER, PASSWORD)
+            .sendMessageWithHeaders(USER, USER,"Short message")
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
index 34ff43d..550dd1d 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
@@ -78,6 +78,8 @@ public class AmqpForwardAttachmentTest {
     public final RuleChain chain = RuleChain.outerRule(temporaryFolder).around(rabbitMqContainer).around(amqpRule);
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
     
     private TemporaryJamesServer jamesServer;
 
@@ -144,15 +146,14 @@ public class AmqpForwardAttachmentTest {
               .recipient(new MailAddress(RECIPIENT))
               .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
         assertThat(amqpRule.readContentAsBytes()).contains(TEST_ATTACHMENT_CONTENT);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
index 52379cd..55d779d 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
@@ -26,7 +26,6 @@ import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
 import static org.apache.james.mailets.configuration.Constants.PASSWORD;
 import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
 import static org.apache.james.mailets.configuration.Constants.calmlyAwait;
-import static org.apache.mailet.base.MailAddressFixture.JAMES_APACHE_ORG;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Optional;
@@ -75,6 +74,8 @@ public class ContactExtractorTest {
     public RuleChain chain = RuleChain.outerRule(rabbit).around(amqpRule).around(folder);
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
@@ -136,22 +137,22 @@ public class ContactExtractorTest {
             .sender(new MailAddress(SENDER))
             .recipients(new MailAddress(TO), new MailAddress(TO2), new MailAddress(CC), new MailAddress(CC2), new MailAddress(BCC), new MailAddress(BCC2))
             .build();
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .authenticate(SENDER, PASSWORD)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(TO, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(TO, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
-            Optional<String> actual = amqpRule.readContent();
-            assertThat(actual).isNotEmpty();
-            assertThatJson(actual.get()).isEqualTo("{"
-                    + "\"userEmail\" : \"sender@james.org\", "
-                    + "\"emails\" : [ \"to@james.org\", \"John To2 <to2@james.org>\", \"cc@james.org\", \"John Cc2 <cc2@james.org>\", \"bcc@james.org\", \"John Bcc2 <bcc2@james.org>\" ]"
-                    + "}");
-        }
+        Optional<String> actual = amqpRule.readContent();
+        assertThat(actual).isNotEmpty();
+        assertThatJson(actual.get()).isEqualTo("{"
+            + "\"userEmail\" : \"sender@james.org\", "
+            + "\"emails\" : [ \"to@james.org\", \"John To2 <to2@james.org>\", \"cc@james.org\", \"John Cc2 <cc2@james.org>\", \"bcc@james.org\", \"John Bcc2 <bcc2@james.org>\" ]"
+            + "}");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
index fddaca5..c70df91 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
@@ -440,6 +440,8 @@ public class ICSAttachmentWorkflowTest {
     public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(rabbitMqContainer).around(amqpRule);
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
     private MimeMessage messageWithoutICSAttached;
@@ -592,15 +594,14 @@ public class ICSAttachmentWorkflowTest {
               .recipient(new MailAddress(RECIPIENT))
               .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
         Optional<String> content = amqpRule.readContent();
         assertThat(content).isPresent();
@@ -629,22 +630,21 @@ public class ICSAttachmentWorkflowTest {
               .recipient(new MailAddress(RECIPIENT))
               .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
-
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
-
-            assertThat(receivedHeaders).doesNotContain("X-MEETING-UID");
-            assertThat(receivedHeaders).doesNotContain("X-MEETING-METHOD");
-            assertThat(receivedHeaders).doesNotContain("X-MEETING-RECURRENCE-ID");
-            assertThat(receivedHeaders).doesNotContain("X-MEETING-SEQUENCE");
-            assertThat(receivedHeaders).doesNotContain("X-MEETING-DTSTAMP");
-        }
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+
+        String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        assertThat(receivedHeaders).doesNotContain("X-MEETING-UID");
+        assertThat(receivedHeaders).doesNotContain("X-MEETING-METHOD");
+        assertThat(receivedHeaders).doesNotContain("X-MEETING-RECURRENCE-ID");
+        assertThat(receivedHeaders).doesNotContain("X-MEETING-SEQUENCE");
+        assertThat(receivedHeaders).doesNotContain("X-MEETING-DTSTAMP");
     }
 
     @Test
@@ -655,21 +655,20 @@ public class ICSAttachmentWorkflowTest {
               .recipient(new MailAddress(RECIPIENT))
               .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
-            assertThat(receivedHeaders).contains("X-MEETING-UID: " + ICS_UID);
-            assertThat(receivedHeaders).contains("X-MEETING-METHOD: " + ICS_METHOD);
-            assertThat(receivedHeaders).contains("X-MEETING-SEQUENCE: " + ICS_SEQUENCE);
-            assertThat(receivedHeaders).contains("X-MEETING-DTSTAMP: " + ICS_DTSTAMP);
-        }
+        String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        assertThat(receivedHeaders).contains("X-MEETING-UID: " + ICS_UID);
+        assertThat(receivedHeaders).contains("X-MEETING-METHOD: " + ICS_METHOD);
+        assertThat(receivedHeaders).contains("X-MEETING-SEQUENCE: " + ICS_SEQUENCE);
+        assertThat(receivedHeaders).contains("X-MEETING-DTSTAMP: " + ICS_DTSTAMP);
     }
 
     @Test
@@ -680,21 +679,20 @@ public class ICSAttachmentWorkflowTest {
             .recipient(new MailAddress(RECIPIENT))
             .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
-            assertThat(receivedHeaders).contains("X-MEETING-UID: " + ICS_BASE64_UID);
-            assertThat(receivedHeaders).contains("X-MEETING-METHOD: " + ICS_METHOD);
-            assertThat(receivedHeaders).contains("X-MEETING-SEQUENCE: " + ICS_SEQUENCE);
-            assertThat(receivedHeaders).contains("X-MEETING-DTSTAMP: " + ICS_BASE64_DTSTAMP);
-        }
+        String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        assertThat(receivedHeaders).contains("X-MEETING-UID: " + ICS_BASE64_UID);
+        assertThat(receivedHeaders).contains("X-MEETING-METHOD: " + ICS_METHOD);
+        assertThat(receivedHeaders).contains("X-MEETING-SEQUENCE: " + ICS_SEQUENCE);
+        assertThat(receivedHeaders).contains("X-MEETING-DTSTAMP: " + ICS_BASE64_DTSTAMP);
     }
 
     @Test
@@ -705,15 +703,14 @@ public class ICSAttachmentWorkflowTest {
             .recipient(new MailAddress(RECIPIENT))
             .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
         Optional<String> content = amqpRule.readContent();
         assertThat(content).isPresent();
@@ -735,15 +732,14 @@ public class ICSAttachmentWorkflowTest {
             .recipient(new MailAddress(RECIPIENT))
             .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
         Optional<String> content = amqpRule.readContent();
         assertThat(content).isPresent();
@@ -766,21 +762,20 @@ public class ICSAttachmentWorkflowTest {
               .recipient(new MailAddress(RECIPIENT))
               .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
-            assertThat(receivedHeaders).contains("X-MEETING-UID: " + ICS_UID);
-            assertThat(receivedHeaders).contains("X-MEETING-METHOD: " + ICS_METHOD);
-            assertThat(receivedHeaders).contains("X-MEETING-SEQUENCE: " + ICS_SEQUENCE);
-            assertThat(receivedHeaders).contains("X-MEETING-DTSTAMP: " + ICS_DTSTAMP);
-        }
+        String receivedHeaders = imapMessageReader.readFirstMessageHeaders();
+        assertThat(receivedHeaders).contains("X-MEETING-UID: " + ICS_UID);
+        assertThat(receivedHeaders).contains("X-MEETING-METHOD: " + ICS_METHOD);
+        assertThat(receivedHeaders).contains("X-MEETING-SEQUENCE: " + ICS_SEQUENCE);
+        assertThat(receivedHeaders).contains("X-MEETING-DTSTAMP: " + ICS_DTSTAMP);
     }
 
     @Test
@@ -791,15 +786,14 @@ public class ICSAttachmentWorkflowTest {
             .recipient(new MailAddress(RECIPIENT))
             .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
 
         Optional<String> content1 = amqpRule.readContent();
         assertThat(content1).isPresent();
@@ -833,16 +827,15 @@ public class ICSAttachmentWorkflowTest {
             .recipient(new MailAddress(RECIPIENT))
             .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            assertThat(imapMessageReader.readFirstMessage())
-                .containsSequence("Content-Type: multipart/mixed", "Content-Disposition: attachment");
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        assertThat(imapMessageReader.readFirstMessage())
+            .containsSequence("Content-Type: multipart/mixed", "Content-Disposition: attachment");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2da49b99/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
index 7849834..c79d02a 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
@@ -62,6 +62,8 @@ public class StripAttachmentTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
 
@@ -136,15 +138,14 @@ public class StripAttachmentTest {
               .recipient(new MailAddress(RECIPIENT))
               .build();
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN)) {
-            messageSender.sendMessage(mail)
-                .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(mail)
+            .awaitSent(calmlyAwait.atMost(ONE_MINUTE));
 
-            imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
-                .login(RECIPIENT, PASSWORD)
-                .select(IMAPMessageReader.INBOX)
-                .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
-            assertThat(imapMessageReader.readFirstMessage()).contains("Matching attachment");
-        }
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(calmlyAwait.atMost(ONE_MINUTE));
+        assertThat(imapMessageReader.readFirstMessage()).contains("Matching attachment");
     }
 }


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


Mime
View raw message