From 7286deb57d06308a158542591751d7819b546810 Mon Sep 17 00:00:00 2001 From: Mindaugas Plukas Date: Fri, 12 Jun 2026 23:08:29 +0300 Subject: [PATCH 1/2] Send message and report success on unknown 2yz recipient error (#199) When option mail.smtp.reportsuccess=true is used --- .../angus/mail/smtp/SMTPUknownCodeTest.java | 66 +++++++++++++++++++ .../angus/mail/smtp/SMTPTransport.java | 2 + 2 files changed, 68 insertions(+) diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java index af8c9c5d..80c96fc1 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java @@ -17,6 +17,7 @@ package org.eclipse.angus.mail.smtp; import jakarta.mail.Message; +import jakarta.mail.MessagingException; import jakarta.mail.Session; import jakarta.mail.Transport; import jakarta.mail.internet.MimeMessage; @@ -26,6 +27,9 @@ import java.io.IOException; import java.util.Properties; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class SMTPUknownCodeTest { @@ -81,4 +85,66 @@ public void rcpt(String line) throws IOException { } } } + + /** + * Test handling of unknown 2xx status code from the server with option mail.smtp.reportsuccess=true + */ + @Test + public void testUnknown2xyWithReportSuccess() { + TestServer server = null; + try { + server = new TestServer(new SMTPLoginHandler() { + @Override + public void rcpt(String line) throws IOException { + if (line.contains("alex")) { + println("254 XY"); + } else { + super.rcpt(line); + } + } + }); + server.start(); + + Properties properties = new Properties(); + properties.setProperty("mail.smtp.host", "localhost"); + properties.setProperty("mail.smtp.port", String.valueOf(server.getPort())); + properties.setProperty("mail.smtp.auth.mechanisms", "LOGIN"); + properties.setProperty("mail.smtp.reportsuccess", "true"); +// properties.setProperty("mail.debug.auth", "true"); + Session session = Session.getInstance(properties); +// session.setDebug(true); + + Transport t = session.getTransport("smtp"); + try { + MimeMessage msg = new MimeMessage(session); + msg.setRecipients(Message.RecipientType.TO, "joe@example.com"); + msg.addRecipients(Message.RecipientType.TO, "alex@example.com"); + msg.setSubject("test"); + msg.setText("test"); + t.connect(); + t.sendMessage(msg, msg.getAllRecipients()); + } catch (SMTPSendFailedException ex) { + // expecting that message sent successfully... + assertEquals(250, ex.getReturnCode()); + // ...to exactly 2 recipients + assertEquals(2, ex.getValidSentAddresses().length); + assertEquals(0, ex.getInvalidAddresses().length); + assertTrue(ex.getNextException() instanceof SMTPAddressSucceededException); + assertTrue(((MessagingException)ex.getNextException()).getNextException() instanceof SMTPAddressSucceededException); + assertNull(((MessagingException)((MessagingException)ex.getNextException()).getNextException()).getNextException()); + } catch (Exception ex) { + fail(ex.toString()); + } finally { + t.close(); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } finally { + if (server != null) { + server.quit(); + server.interrupt(); + } + } + } } diff --git a/providers/smtp/src/main/java/org/eclipse/angus/mail/smtp/SMTPTransport.java b/providers/smtp/src/main/java/org/eclipse/angus/mail/smtp/SMTPTransport.java index 95aa25b7..d2c25402 100644 --- a/providers/smtp/src/main/java/org/eclipse/angus/mail/smtp/SMTPTransport.java +++ b/providers/smtp/src/main/java/org/eclipse/angus/mail/smtp/SMTPTransport.java @@ -1977,6 +1977,8 @@ protected void rcptTo() throws MessagingException { mex = sfex; else mex.setNextException(sfex); + + break; } else { // completely unexpected response, just give up if (logger.isLoggable(Level.FINE)) From 51eed91ff4a64e24cba2836e30eaa0ed9e8a27f4 Mon Sep 17 00:00:00 2001 From: Mindaugas Plukas Date: Sat, 13 Jun 2026 11:24:47 +0300 Subject: [PATCH 2/2] test adjustment (#199) --- .../java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java index 80c96fc1..e14f281f 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/smtp/SMTPUknownCodeTest.java @@ -123,6 +123,7 @@ public void rcpt(String line) throws IOException { msg.setText("test"); t.connect(); t.sendMessage(msg, msg.getAllRecipients()); + fail("Success report SMTPSendFailedException expected"); } catch (SMTPSendFailedException ex) { // expecting that message sent successfully... assertEquals(250, ex.getReturnCode());