james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [19/24] james-project git commit: JAMES-2366 Fix error handling in SMTPMessageSender
Date Fri, 20 Apr 2018 02:13:04 GMT
JAMES-2366 Fix error handling in SMTPMessageSender

We need step by step checks with an error fully describing what happened.

Also, sending a mail with this tool is synchronous. Our code should reflect this.


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

Branch: refs/heads/master
Commit: cf91dd4cbc2f21f4721ad995fc257df81c5880e6
Parents: 696929b
Author: benwa <btellier@linagora.com>
Authored: Thu Apr 19 10:56:05 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Apr 20 09:12:02 2018 +0700

----------------------------------------------------------------------
 .../CassandraMailRepositoryIntegrationTest.java |   3 +-
 .../org/apache/james/JPAJamesServerTest.java    |   3 +-
 .../james/mailets/AddDeliveredToHeaderTest.java |   3 +-
 .../mailets/CommonMailetConfigurationTest.java  |   3 +-
 .../mailets/NetworkMatcherIntegrationTest.java  |  24 ++---
 .../RecipientRewriteTableIntegrationTest.java   |  24 ++---
 .../org/apache/james/mailets/SieveDelivery.java |   3 +-
 .../james/mailets/SmtpAuthIntegrationTest.java  |   6 +-
 .../crypto/SMIMEDecryptIntegrationTest.java     |   9 +-
 .../crypto/SMIMESignIntegrationTest.java        |   6 +-
 .../james/smtp/SmtpAuthorizedAddressesTest.java |  21 ++--
 .../james/smtp/SmtpBracketEnforcementTest.java  |  22 ++--
 .../smtp/SmtpIdentityVerificationTest.java      |  19 ++--
 .../apache/james/smtp/SmtpNullSenderTest.java   |   6 +-
 .../james/smtp/SmtpSizeLimitationTest.java      |  16 +--
 .../james/transport/mailets/AddFooterTest.java  |   6 +-
 .../mailets/AmqpForwardAttachmentTest.java      |   3 +-
 .../transport/mailets/ContactExtractorTest.java |   3 +-
 .../transport/mailets/GroupMappingTest.java     |  61 +++++------
 .../mailets/ICSAttachmentWorkflowTest.java      |  30 ++----
 .../mailets/IsOverQuotaMatcherTest.java         |  18 ++--
 .../transport/mailets/SpamAssassinTest.java     |  12 +--
 .../transport/mailets/StripAttachmentTest.java  |   3 +-
 .../transport/mailets/ToRepositoryTest.java     |  12 +--
 .../integration/SetMessagesMethodTest.java      |   2 -
 .../apache/james/utils/SMTPMessageSender.java   | 108 ++++++++-----------
 .../james/utils/SMTPSendingException.java       |  73 +++++++++++++
 .../org/apache/james/utils/SmtpSendingStep.java |  28 +++++
 28 files changed, 272 insertions(+), 255 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
index 81972d1..3d5db0c 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
@@ -69,8 +69,7 @@ public class CassandraMailRepositoryIntegrationTest {
         server.getProbe(DataProbeImpl.class).addUser("user@domain.com", "secret");
 
         smtpMessageSender.connect("127.0.0.1", 1025)
-            .sendMessage("denied@other.com", "user@domain.com")
-            .awaitSent(await);
+            .sendMessage("denied@other.com", "user@domain.com");
 
         MailRepositoryProbeImpl repositoryProbe = server.getProbe(MailRepositoryProbeImpl.class);
         await.until(() -> repositoryProbe.getRepositoryMailCount("cassandra://var/mail/sender-denied/") == 1);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
index 91d1d49..ee2144f 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -78,8 +78,7 @@ public class JPAJamesServerTest extends AbstractJamesServerTest {
 
         // ~ 12 KB email
         smtpMessageSender.connect(LOCALHOST, SMTP_PORT)
-            .sendMessageWithHeaders(USER, USER, "header: toto\\r\\n\\r\\n" + Strings.repeat("0123456789\n", 1024))
-            .awaitSent(AWAIT);
+            .sendMessageWithHeaders(USER, USER, "header: toto\\r\\n\\r\\n" + Strings.repeat("0123456789\n", 1024));
         AWAIT.until(() -> imapMessageReader.connect(LOCALHOST, IMAP_PORT)
             .login(USER, PASSWORD)
             .select(IMAPMessageReader.INBOX)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 f173489..469f0f0 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
@@ -67,8 +67,7 @@ public class AddDeliveredToHeaderTest {
     @Test
     public void receivedMessagesShouldContainDeliveredToHeaders() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 d45f29c..0861fdb 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
@@ -69,8 +69,7 @@ public class CommonMailetConfigurationTest {
     @Test
     public void simpleMailShouldBeSent() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
index e844d54..7fcc013 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
@@ -97,8 +97,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -118,8 +117,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -139,8 +137,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -160,8 +157,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -181,8 +177,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -202,8 +197,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -223,8 +217,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         MailRepositoryProbeImpl repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
         awaitAtMostOneMinute.until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1);
@@ -248,8 +241,7 @@ public class NetworkMatcherIntegrationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         MailRepositoryProbeImpl repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
         awaitAtMostOneMinute.until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 fb859aa..4bc8a3c 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
@@ -82,8 +82,7 @@ public class RecipientRewriteTableIntegrationTest {
     @Test
     public void rrtServiceShouldNotImpactRecipientsNotMatchingAnyRRT() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -98,8 +97,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addAddressMapping(RECIPIENT_LOCAL_PART, DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(ANY_AT_JAMES, PASSWORD)
@@ -119,8 +117,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addAddressMapping(RECIPIENT_LOCAL_PART, DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -139,8 +136,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addAddressMapping(RECIPIENT_LOCAL_PART, DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(localUser, PASSWORD)
@@ -160,8 +156,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addUser(ANY_AT_ANOTHER_DOMAIN, PASSWORD);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, ANY_AT_JAMES)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, ANY_AT_JAMES);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(ANY_AT_ANOTHER_DOMAIN, PASSWORD)
@@ -176,8 +171,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addUser(ANY_AT_ANOTHER_DOMAIN, PASSWORD);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, ANY_AT_JAMES)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, ANY_AT_JAMES);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(ANY_AT_JAMES, PASSWORD)
@@ -192,8 +186,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addForwardMapping(RECIPIENT_LOCAL_PART, DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(ANY_AT_JAMES, PASSWORD)
@@ -213,8 +206,7 @@ public class RecipientRewriteTableIntegrationTest {
         dataProbe.addForwardMapping(ANY_LOCAL_PART, DEFAULT_DOMAIN, OTHER_AT_JAMES);
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, GROUP)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, GROUP);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(OTHER_AT_JAMES, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 cfe116b..c2706f9 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
@@ -78,8 +78,7 @@ public class SieveDelivery {
             "fileinto \"" + TARGETED_MAILBOX + "\";");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 89dee69..0796b77 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
@@ -103,8 +103,7 @@ public class SmtpAuthIntegrationTest {
     public void authenticatedSmtpSessionsShouldBeDelivered() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -115,8 +114,7 @@ public class SmtpAuthIntegrationTest {
     @Test
     public void nonAuthenticatedSmtpSessionsShouldNotBeDelivered() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, FROM);
 
         awaitAtMostOneMinute.until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1);
         assertThat(

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 e1b2d57..554e0d5 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
@@ -99,8 +99,7 @@ public class SMIMEDecryptIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
             .authenticate(FROM, PASSWORD)
             .sendMessageWithHeaders(FROM, FROM,
-                ClassLoaderUtils.getSystemResourceAsString("eml/crypted.eml"))
-            .awaitSent(awaitAtMostOneMinute);
+                ClassLoaderUtils.getSystemResourceAsString("eml/crypted.eml"));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -114,8 +113,7 @@ public class SMIMEDecryptIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
             .authenticate(FROM, PASSWORD)
             .sendMessageWithHeaders(FROM, FROM,
-                ClassLoaderUtils.getSystemResourceAsString("eml/crypted_with_attachment.eml"))
-            .awaitSent(awaitAtMostOneMinute);
+                ClassLoaderUtils.getSystemResourceAsString("eml/crypted_with_attachment.eml"));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -130,8 +128,7 @@ public class SMIMEDecryptIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
             .authenticate(FROM, PASSWORD)
             .sendMessageWithHeaders(FROM, FROM,
-                ClassLoaderUtils.getSystemResourceAsString("eml/bad_crypted.eml"))
-            .awaitSent(awaitAtMostOneMinute);
+                ClassLoaderUtils.getSystemResourceAsString("eml/bad_crypted.eml"));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
index 859ee94..669248f 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
@@ -114,8 +114,7 @@ public class SMIMESignIntegrationTest {
     public void authenticatedMessagesShouldBeSigned() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -128,8 +127,7 @@ public class SMIMESignIntegrationTest {
     @Test
     public void nonAuthenticatedMessagesShouldNotBeSigned() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_SECURE_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 bdc6e39..859325d 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
@@ -25,6 +25,7 @@ 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.awaitAtMostOneMinute;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasSize;
 
@@ -41,6 +42,8 @@ import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.FakeSmtp;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SMTPSendingException;
+import org.apache.james.utils.SmtpSendingStep;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -63,7 +66,7 @@ public class SmtpAuthorizedAddressesTest {
     private TemporaryJamesServer jamesServer;
 
     @Before
-    public void setup() throws Exception {
+    public void setup() {
         fakeSmtp.awaitStarted(awaitAtMostOneMinute);
     }
 
@@ -101,8 +104,7 @@ public class SmtpAuthorizedAddressesTest {
             .withAutorizedAddresses("127.0.0.0/8"));
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, TO)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, TO);
 
         awaitAtMostOneMinute.until(() -> fakeSmtp.isReceived(response -> response
             .body("", hasSize(1))
@@ -116,9 +118,10 @@ public class SmtpAuthorizedAddressesTest {
             .requireAuthentication()
             .withAutorizedAddresses("172.0.0.0/8"));
 
-        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, TO)
-            .awaitSentFail(awaitAtMostOneMinute);
+        assertThatThrownBy(() ->
+            messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+                .sendMessage(FROM, TO))
+            .isEqualTo(new SMTPSendingException(SmtpSendingStep.RCPT, "530 5.7.1 Authentication Required\n"));
     }
 
     @Test
@@ -129,8 +132,7 @@ public class SmtpAuthorizedAddressesTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(FROM, PASSWORD)
-            .sendMessage(FROM, TO)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, TO);
 
         awaitAtMostOneMinute.until(() -> fakeSmtp.isReceived(response -> response
             .body("", hasSize(1))
@@ -145,8 +147,7 @@ public class SmtpAuthorizedAddressesTest {
             .withAutorizedAddresses("172.0.0.0/8"));
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(TO, FROM)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(TO, FROM);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 4f2832b..a974d3f 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
@@ -23,13 +23,15 @@ import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
 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.awaitAtMostOneMinute;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.mailets.TemporaryJamesServer;
 import org.apache.james.mailets.configuration.SmtpConfiguration;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SMTPSendingException;
+import org.apache.james.utils.SmtpSendingStep;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
@@ -69,8 +71,7 @@ public class SmtpBracketEnforcementTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(USER, PASSWORD)
-            .sendMessage(USER, USER)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(USER, USER);
     }
 
     @Test
@@ -80,8 +81,7 @@ public class SmtpBracketEnforcementTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(USER, PASSWORD)
-            .sendMessageNoBracket(USER, USER)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessageNoBracket(USER, USER);
     }
 
     @Test
@@ -91,8 +91,7 @@ public class SmtpBracketEnforcementTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(USER, PASSWORD)
-            .sendMessage(USER, USER)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(USER, USER);
     }
 
     @Test
@@ -100,9 +99,10 @@ public class SmtpBracketEnforcementTest {
         createJamesServer(SmtpConfiguration.builder()
             .requireBracketEnforcement());
 
-        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .authenticate(USER, PASSWORD)
-            .sendMessageNoBracket(USER, USER)
-            .awaitSentFail(awaitAtMostOneMinute);
+        assertThatThrownBy(() ->
+            messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+                .authenticate(USER, PASSWORD)
+                .sendMessageNoBracket(USER, USER))
+            .isEqualTo(new SMTPSendingException(SmtpSendingStep.RCPT, "501 5.5.2 Syntax error in parameters or arguments\n"));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 5a8582d..1a7d323 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
@@ -23,13 +23,15 @@ import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
 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.awaitAtMostOneMinute;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.mailets.TemporaryJamesServer;
 import org.apache.james.mailets.configuration.SmtpConfiguration;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SMTPSendingException;
+import org.apache.james.utils.SmtpSendingStep;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
@@ -73,8 +75,7 @@ public class SmtpIdentityVerificationTest {
             .verifyIdentity());
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .authenticate(USER, PASSWORD).sendMessage(USER, USER)
-            .awaitSent(awaitAtMostOneMinute);
+            .authenticate(USER, PASSWORD).sendMessage(USER, USER);
     }
 
     @Test
@@ -85,8 +86,7 @@ public class SmtpIdentityVerificationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(ATTACKER, ATTACKER_PASSWORD)
-            .sendMessage(USER, USER)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(USER, USER);
     }
 
     @Test
@@ -95,10 +95,11 @@ public class SmtpIdentityVerificationTest {
             .requireAuthentication()
             .verifyIdentity());
 
-        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .authenticate(ATTACKER, ATTACKER_PASSWORD)
-            .sendMessage(USER, USER)
-            .awaitSentFail(awaitAtMostOneMinute);
+        assertThatThrownBy(() ->
+            messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+                .authenticate(ATTACKER, ATTACKER_PASSWORD)
+                .sendMessage(USER, USER))
+            .isEqualTo(new SMTPSendingException(SmtpSendingStep.RCPT, "503 5.7.1 Incorrect Authentication for Specified Email Address\n"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
index b6b6d80..2bcb837 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
@@ -67,15 +67,13 @@ public class SmtpNullSenderTest {
     @Test
     public void smtpLayerShouldAcceptEmptySenders() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessageWithHeaders("", USER,"Short message")
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessageWithHeaders("", USER,"Short message");
     }
 
     @Test
     public void mailProcessingShouldDeliverNullSender() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessageWithHeaders("", USER,"Short message")
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessageWithHeaders("", USER,"Short message");
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 28b31ea..bc5aea9 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
@@ -23,13 +23,15 @@ import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
 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.awaitAtMostOneMinute;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.mailets.TemporaryJamesServer;
 import org.apache.james.mailets.configuration.SmtpConfiguration;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SMTPSendingException;
+import org.apache.james.utils.SmtpSendingStep;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
@@ -70,10 +72,11 @@ public class SmtpSizeLimitationTest {
             .doNotVerifyIdentity()
             .withMaxMessageSizeInKb(10));
 
-        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .authenticate(USER, PASSWORD)
-            .sendMessageWithHeaders(USER, USER, Strings.repeat("Long message", 1024))
-            .awaitSentFail(awaitAtMostOneMinute);
+        assertThatThrownBy(() ->
+            messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+                .authenticate(USER, PASSWORD)
+                .sendMessageWithHeaders(USER, USER, Strings.repeat("Long message", 1024)))
+            .isEqualTo(new SMTPSendingException(SmtpSendingStep.Data, "500 Line length exceeded. See RFC 2821 #4.5.3.1.\n"));
     }
 
     @Test
@@ -84,7 +87,6 @@ public class SmtpSizeLimitationTest {
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .authenticate(USER, PASSWORD)
-            .sendMessageWithHeaders(USER, USER,"Short message")
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessageWithHeaders(USER, USER,"Short message");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
index 3e35051..88adc4e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
@@ -90,8 +90,7 @@ public class AddFooterTest {
                     .setText("Any content")
                     .setSubject("test"))
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -115,8 +114,7 @@ public class AddFooterTest {
                             .type("application/data"))
                     .setSubject("test"))
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 b67d4eb..c876847 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
@@ -130,8 +130,7 @@ public class AmqpForwardAttachmentTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 ba6bda2..050e177 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
@@ -125,8 +125,7 @@ public class ContactExtractorTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipients(TO, TO2, CC, CC2, BCC, BCC2))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipients(TO, TO2, CC, CC2, BCC, BCC2));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(TO, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
index 2339ca5..cd9606e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
@@ -27,6 +27,7 @@ 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.awaitAtMostOneMinute;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.hamcrest.Matchers.equalTo;
 
 import javax.mail.internet.MimeMessage;
@@ -41,13 +42,14 @@ import org.apache.james.mailets.configuration.MailetContainer;
 import org.apache.james.mailets.configuration.ProcessorConfiguration;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
-import org.apache.james.protocols.smtp.SMTPRetCode;
 import org.apache.james.transport.matchers.All;
 import org.apache.james.transport.matchers.RecipientIsLocal;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.FakeSmtp;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SMTPSendingException;
+import org.apache.james.utils.SmtpSendingStep;
 import org.apache.james.utils.WebAdminGuiceProbe;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.routes.GroupsRoutes;
@@ -143,8 +145,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -161,8 +162,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN2, PASSWORD)
@@ -181,8 +181,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -204,8 +203,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN2, PASSWORD)
@@ -226,8 +224,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -243,8 +240,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipients(GROUP_ON_DOMAIN1, USER_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipients(GROUP_ON_DOMAIN1, USER_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -264,8 +260,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN2, PASSWORD)
@@ -288,12 +283,15 @@ public class GroupMappingTest {
 
         webAdminApi.put(GroupsRoutes.ROOT_PATH + "/" + GROUP_ON_DOMAIN2 + "/" + GROUP_ON_DOMAIN1);
 
-        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendEnvelope(FakeMail.builder()
-                .mimeMessage(message)
-                .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSentFail(SMTPRetCode.MAILBOX_PERM_UNAVAILABLE, awaitAtMostOneMinute);
+
+        assertThatThrownBy(() ->
+            messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+                .sendMessage(FakeMail.builder()
+                    .mimeMessage(message)
+                    .sender(SENDER)
+                    .recipient(GROUP_ON_DOMAIN1)))
+            .isInstanceOf(SMTPSendingException.class)
+            .matches(t -> SMTPSendingException.isForStep(t, SmtpSendingStep.RCPT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -316,8 +314,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN2, PASSWORD)
@@ -335,8 +332,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -354,8 +350,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient((GROUP_ON_DOMAIN1)))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient((GROUP_ON_DOMAIN1)));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN2, PASSWORD)
@@ -373,8 +368,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(groupWithSlash))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(groupWithSlash));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -393,8 +387,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(userWithSlash, PASSWORD)
@@ -412,8 +405,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(USER_DOMAIN1, PASSWORD)
@@ -430,8 +422,7 @@ public class GroupMappingTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(SENDER)
-                .recipient(GROUP_ON_DOMAIN1))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(GROUP_ON_DOMAIN1));
 
         fakeSmtp.isReceived(response -> response
             .body("[0].from", equalTo(SENDER))

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 cc78ded..8c8a794 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
@@ -558,8 +558,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithoutICSAttached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -575,8 +574,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithICSAttached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -608,8 +606,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithoutICSAttached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -630,8 +627,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithICSAttached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -651,8 +647,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithICSBase64Attached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -672,8 +667,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithICSBase64Attached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -698,8 +692,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(yahooInvitationMessage)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -725,8 +718,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithThreeICSAttached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -746,8 +738,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(messageWithThreeICSAttached)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -785,8 +776,7 @@ public class ICSAttachmentWorkflowTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(calendarMessage)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
index f6e7850..26a3658 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
@@ -116,8 +116,7 @@ public class IsOverQuotaMatcherTest {
             .put("/quota/users/" + RECIPIENT + "/size");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         IMAPMessageReader messageReader = imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -135,8 +134,7 @@ public class IsOverQuotaMatcherTest {
             .put("/quota/domains/" + DEFAULT_DOMAIN + "/size");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         IMAPMessageReader messageReader = imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -154,8 +152,7 @@ public class IsOverQuotaMatcherTest {
             .put("/quota/users/" + RECIPIENT + "/size");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -170,8 +167,7 @@ public class IsOverQuotaMatcherTest {
             .put("/quota/users/" + RECIPIENT + "/count");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         IMAPMessageReader messageReader = imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -189,8 +185,7 @@ public class IsOverQuotaMatcherTest {
             .put("/quota/domains/" + DEFAULT_DOMAIN + "/count");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         IMAPMessageReader messageReader = imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(FROM, PASSWORD)
@@ -208,8 +203,7 @@ public class IsOverQuotaMatcherTest {
             .put("/quota/users/" + RECIPIENT + "/count");
 
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(FROM, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(FROM, RECIPIENT);
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/SpamAssassinTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/SpamAssassinTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/SpamAssassinTest.java
index 970fe48..8ed9729 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/SpamAssassinTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/SpamAssassinTest.java
@@ -101,8 +101,7 @@ public class SpamAssassinTest {
     @Test
     public void spamAssassinShouldAppendNewHeaderOnMessage() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(mailWithContent("This is the content", RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(mailWithContent("This is the content", RECIPIENT));
 
         messageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -118,8 +117,7 @@ public class SpamAssassinTest {
     @Test
     public void spamAssassinShouldAppendNewHeaderWhichDetectIsSpamWhenSpamMessage() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(mailWithContent(SPAM_CONTENT, RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(mailWithContent(SPAM_CONTENT, RECIPIENT));
 
         messageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -134,8 +132,7 @@ public class SpamAssassinTest {
     @Test
     public void spamAssassinShouldAppendNewHeaderWhichNoWhenNonSpamMessage() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(mailWithContent("This is the content", RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(mailWithContent("This is the content", RECIPIENT));
 
         messageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)
@@ -150,8 +147,7 @@ public class SpamAssassinTest {
     @Test
     public void spamAssassinShouldAppendNewHeaderPerRecipientOnMessage() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
-            .sendMessage(mailWithContent("This is the content", RECIPIENT, RECIPIENT2))
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(mailWithContent("This is the content", RECIPIENT, RECIPIENT2));
 
         messageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/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 9e35168..5ed44b3 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
@@ -122,8 +122,7 @@ public class StripAttachmentTest {
             .sendMessage(FakeMail.builder()
                 .mimeMessage(message)
                 .sender(FROM)
-                .recipient(RECIPIENT))
-            .awaitSent(awaitAtMostOneMinute);
+                .recipient(RECIPIENT));
 
         imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
             .login(RECIPIENT, PASSWORD)

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
index 4a4edb5..ede133d 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
@@ -99,9 +99,7 @@ public class ToRepositoryTest {
     public void incomingShouldBeStoredInProcessorByDefault() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(RECIPIENT, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute)
-            .sendMessage(RECIPIENT, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(RECIPIENT, RECIPIENT);
 
         awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 2);
     }
@@ -110,9 +108,7 @@ public class ToRepositoryTest {
     public void userShouldBeAbleToAccessReprocessedMails() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(RECIPIENT, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute)
-            .sendMessage(RECIPIENT, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(RECIPIENT, RECIPIENT);
 
         awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 2);
 
@@ -138,9 +134,7 @@ public class ToRepositoryTest {
     public void userShouldBeAbleToAccessReprocessedMail() throws Exception {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(RECIPIENT, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute)
-            .sendMessage(RECIPIENT, RECIPIENT)
-            .awaitSent(awaitAtMostOneMinute);
+            .sendMessage(RECIPIENT, RECIPIENT);
 
         awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 2);
         String key = probe.listMailKeys(CUSTOM_REPOSITORY).get(0);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 0c2a08c..d484a10 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -117,7 +117,6 @@ import org.junit.Test;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.io.ByteStreams;
-import com.jayway.awaitility.Duration;
 import com.jayway.restassured.RestAssured;
 import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.builder.ResponseSpecBuilder;
@@ -5390,7 +5389,6 @@ public abstract class SetMessagesMethodTest {
             .build();
         try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DOMAIN)) {
             messageSender.sendMessage(mail);
-            calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent);
         }
 
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until(() -> isAnyMessageFoundInInbox(accessToken));

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
index 723f4e1..8d132a9 100644
--- a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
+++ b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
@@ -38,7 +38,6 @@ import org.junit.rules.ExternalResource;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Throwables;
-import com.jayway.awaitility.core.ConditionFactory;
 
 public class SMTPMessageSender extends ExternalResource implements Closeable {
 
@@ -85,17 +84,17 @@ public class SMTPMessageSender extends ExternalResource implements Closeable {
 
     public SMTPMessageSender authenticate(String username, String password) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException {
         if (smtpClient.auth(AuthenticatingSMTPClient.AUTH_METHOD.PLAIN, username, password) == false) {
-            throw new RuntimeException("auth failed");
+            throw new SMTPSendingException(SmtpSendingStep.Authentication, smtpClient.getReplyString());
         }
         return this;
     }
 
     public SMTPMessageSender sendMessage(String from, String recipient) {
         try {
-            smtpClient.helo(senderDomain);
-            smtpClient.setSender(from);
-            smtpClient.rcpt("<" + recipient + ">");
-            smtpClient.sendShortMessageData("FROM: " + from + "\r\n" +
+            doHelo();
+            doSetSender(from);
+            doRCPT("<" + recipient + ">");
+            doData("FROM: " + from + "\r\n" +
                 "subject: test\r\n" +
                 "\r\n" +
                 "content\r\n" +
@@ -108,10 +107,10 @@ public class SMTPMessageSender extends ExternalResource implements Closeable {
 
     public SMTPMessageSender sendMessageNoBracket(String from, String recipient) {
         try {
-            smtpClient.helo(senderDomain);
-            smtpClient.setSender(from);
-            smtpClient.rcpt(recipient);
-            smtpClient.sendShortMessageData("FROM: " + from + "\r\n" +
+            doHelo();
+            doSetSender(from);
+            doRCPT(recipient);
+            doData("FROM: " + from + "\r\n" +
                 "subject: test\r\n" +
                 "\r\n" +
                 "content\r\n" +
@@ -124,10 +123,10 @@ public class SMTPMessageSender extends ExternalResource implements Closeable {
 
     public SMTPMessageSender sendMessageWithHeaders(String from, String recipient, String message) {
         try {
-            smtpClient.helo(senderDomain);
-            smtpClient.setSender(from);
-            smtpClient.rcpt("<" + recipient + ">");
-            smtpClient.sendShortMessageData(message);
+            doHelo();
+            doSetSender(from);
+            doRCPT("<" + recipient + ">");
+            doData(message);
         } catch (IOException e) {
             throw Throwables.propagate(e);
         }
@@ -137,37 +136,19 @@ public class SMTPMessageSender extends ExternalResource implements Closeable {
     public SMTPMessageSender sendMessage(Mail mail) throws MessagingException {
         try {
             String from = mail.getSender().asString();
-            smtpClient.helo(senderDomain);
-            smtpClient.setSender(from);
+            doHelo();
+            doSetSender(from);
             mail.getRecipients().stream()
                 .map(MailAddress::asString)
-                .forEach(Throwing.consumer(smtpClient::addRecipient));
-            smtpClient.sendShortMessageData(asString(mail.getMessage()));
+                .forEach(Throwing.consumer(this::doAddRcpt));
+            doData(asString(mail.getMessage()));
         } catch (IOException e) {
             throw Throwables.propagate(e);
         }
         return this;
     }
 
-    public SMTPMessageSender sendEnvelope(Mail mail) throws MessagingException {
-        try {
-            String from = mail.getSender().asString();
-            smtpClient.helo(senderDomain);
-            smtpClient.setSender(from);
-            mail.getRecipients().stream()
-                .map(MailAddress::asString)
-                .forEach(Throwing.consumer(smtpClient::addRecipient));
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
-        return this;
-    }
-
-    public SMTPMessageSender sendEnvelope(FakeMail.Builder mail) throws MessagingException {
-        return sendEnvelope(mail.build());
-    }
-
-    public SMTPMessageSender sendMessage(FakeMail.Builder mail) throws MessagingException {
+    public SMTPMessageSender sendMessage(FakeMail.Builder mail) throws MessagingException, IOException {
         return sendMessage(mail.build());
     }
 
@@ -177,40 +158,43 @@ public class SMTPMessageSender extends ExternalResource implements Closeable {
         return new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
     }
 
-    public boolean messageHasBeenSent() throws IOException {
-        return smtpClient.getReplyString()
-            .contains("250 2.6.0 Message received");
-    }
-
-    public SMTPMessageSender awaitSent(ConditionFactory conditionFactory) {
-        conditionFactory.until(this::messageHasBeenSent);
-        return this;
-    }
-
-    public void awaitSentFail(ConditionFactory conditionFactory) {
-        conditionFactory.until(this::messageSendingFailed);
+    @Override
+    public void close() throws IOException {
+        smtpClient.disconnect();
     }
 
-    public void awaitSentFail(String code, ConditionFactory conditionFactory) {
-        conditionFactory.until(() -> messageSendingFailedWithCode(code));
+    private void doSetSender(String from) throws IOException {
+        boolean success = smtpClient.setSender(from);
+        if (!success) {
+            throw new SMTPSendingException(SmtpSendingStep.Sender, smtpClient.getReplyString());
+        }
     }
 
-    public boolean messageSendingFailed() {
-        String replyString = smtpClient.getReplyString().trim();
-        return replyString.startsWith("4") || replyString.startsWith("5");
+    private void doHelo() throws IOException {
+        int code = smtpClient.helo(senderDomain);
+        if (code != 250) {
+            throw new SMTPSendingException(SmtpSendingStep.Helo, smtpClient.getReplyString());
+        }
     }
 
-    public boolean messageSendingFailedWithCode(String code) {
-        String replyString = smtpClient.getReplyString().trim();
-        return replyString.startsWith(code);
+    private void doRCPT(String recipient) throws IOException {
+        int code = smtpClient.rcpt(recipient);
+        if (code != 250) {
+            throw new SMTPSendingException(SmtpSendingStep.RCPT, smtpClient.getReplyString());
+        }
     }
 
-    public boolean messageHaveNotBeenSent() throws IOException {
-        return !messageHasBeenSent();
+    private void doData(String message) throws IOException {
+        boolean success = smtpClient.sendShortMessageData(message);
+        if (!success) {
+            throw new SMTPSendingException(SmtpSendingStep.Data, smtpClient.getReplyString());
+        }
     }
 
-    @Override
-    public void close() throws IOException {
-        smtpClient.disconnect();
+    private void doAddRcpt(String rcpt) throws IOException {
+        boolean success = smtpClient.addRecipient(rcpt);
+        if (!success) {
+            throw new SMTPSendingException(SmtpSendingStep.RCPT, smtpClient.getReplyString());
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/testing/src/main/java/org/apache/james/utils/SMTPSendingException.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPSendingException.java b/server/testing/src/main/java/org/apache/james/utils/SMTPSendingException.java
new file mode 100644
index 0000000..42be74e
--- /dev/null
+++ b/server/testing/src/main/java/org/apache/james/utils/SMTPSendingException.java
@@ -0,0 +1,73 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.utils;
+
+import java.util.List;
+import java.util.Objects;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+
+public class SMTPSendingException extends RuntimeException {
+
+    public static boolean isForStep(Throwable t, SmtpSendingStep step) {
+        if (t instanceof SMTPSendingException) {
+            SMTPSendingException e = (SMTPSendingException) t;
+            return e.sendingStep.equals(step);
+        }
+        return false;
+    }
+
+    private static String sanitizeString(String lastServerMessage) {
+        List<String> lines = Splitter.on("\r\n")
+            .trimResults()
+            .omitEmptyStrings()
+            .splitToList(lastServerMessage);
+
+        return Joiner.on("\n")
+            .skipNulls()
+            .join(lines);
+    }
+
+    private final SmtpSendingStep sendingStep;
+    private final String lastServerMessage;
+
+    public SMTPSendingException(SmtpSendingStep sendingStep, String lastServerMessage) {
+        super(String.format("Error upon step %s: %s", sendingStep, lastServerMessage));
+        this.sendingStep = sendingStep;
+        this.lastServerMessage = sanitizeString(lastServerMessage);
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof SMTPSendingException) {
+            SMTPSendingException that = (SMTPSendingException) o;
+
+            return Objects.equals(this.sendingStep, that.sendingStep)
+                && Objects.equals(this.lastServerMessage, that.lastServerMessage);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(sendingStep, lastServerMessage);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cf91dd4c/server/testing/src/main/java/org/apache/james/utils/SmtpSendingStep.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SmtpSendingStep.java b/server/testing/src/main/java/org/apache/james/utils/SmtpSendingStep.java
new file mode 100644
index 0000000..51b9b8d
--- /dev/null
+++ b/server/testing/src/main/java/org/apache/james/utils/SmtpSendingStep.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.utils;
+
+public enum SmtpSendingStep {
+    Authentication,
+    Helo,
+    RCPT,
+    Sender,
+    Data
+}


---------------------------------------------------------------------
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