/*** * Logout of the SMTP server by sending the QUIT command. * <p> * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException * If the SMTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send SMTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @throws IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean logout() throws IOException { return SMTPReply.isPositiveCompletion(quit()); }
/*** * Logout of the SMTP server by sending the QUIT command. * <p> * @return True if successfully completed, false if not. * @exception SMTPConnectionClosedException * If the SMTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send SMTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean logout() throws IOException { return SMTPReply.isPositiveCompletion(quit()); }
/*** * Logout of the SMTP server by sending the QUIT command. * <p> * @return True if successfully completed, false if not. * @exception SMTPConnectionClosedException * If the SMTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send SMTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean logout() throws IOException { return SMTPReply.isPositiveCompletion(quit()); }
private void ensureIsDisconnected(SMTPClient client) throws IOException, InterruptedException { int initialConnections = smtpServer.getCurrentConnections(); client.quit(); client.disconnect(); assertIsDisconnected(initialConnections); }
@Test public void testSenderDomainResolvDefault() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); String sender1 = "mail_sender1@xfwrqqfgfe.de"; smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
@Test public void testEhloResolvDefault() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol1.sendCommand("ehlo", "abgsfe3rsf.de"); // ehlo should not be checked. so this should give a 250 code assertThat(smtpProtocol1.getReplyCode()) .as("ehlo accepted") .isEqualTo(250); smtpProtocol1.quit(); }
@Test public void testHeloResolvDefault() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol1.helo("abgsfe3rsf.de"); // helo should not be checked. so this should give a 250 code assertThat(smtpProtocol1.getReplyCode()) .as("Helo accepted") .isEqualTo(250); smtpProtocol1.quit(); }
@Test public void testMaxRcptDefault() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); String sender1 = "mail_sender1@james.apache.org"; String rcpt1 = "test@localhost"; smtpProtocol1.setSender(sender1); smtpProtocol1.addRecipient(rcpt1); smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body testMaxRcptDefault\r\n"); smtpProtocol1.quit(); }
@Test public void testAuthCancel() throws Exception { smtpConfiguration.setAuthorizedAddresses("127.0.0.1/8"); smtpConfiguration.setAuthorizingAnnounce(); init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); smtpProtocol.sendCommand("AUTH PLAIN"); assertThat(smtpProtocol.getReplyCode()) .as("start auth.") .isEqualTo(334); smtpProtocol.sendCommand("*"); assertThat(smtpProtocol.getReplyCode()) .as("cancel auth.") .isEqualTo(501); smtpProtocol.quit(); }
@Test public void testSenderDomainResolvRelayClientDefault() throws Exception { smtpConfiguration.setSenderDomainResolv(); init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(smtpProtocol1.isConnected()) .as("first connection taken") .isTrue(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); String sender1 = "mail_sender1@xfwrqqfgfe.de"; // Both mail shold smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
@Test public void testHeloEnforcement() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(smtpProtocol1.isConnected()) .as("first connection taken") .isTrue(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); String sender1 = "mail_sender1@localhost"; smtpProtocol1.setSender(sender1); assertThat(smtpProtocol1.getReplyCode()) .as("expected 503 error") .isEqualTo(503); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
private void send(ProtocolServer server, InetSocketAddress bindedAddress, String msg) throws SocketException, IOException { SMTPClient client = createClient(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.helo("localhost"); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.setSender(SENDER); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT1); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT2); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(client.sendShortMessageData(msg)).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); }
private void send(ProtocolServer server, InetSocketAddress bindedAddress, String msg) throws SocketException, IOException { SMTPClient client = createClient(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.helo("localhost"); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.setSender(SENDER); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT1); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT2); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(client.sendShortMessageData(msg)).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); }
@Test public void testHeloEnforcementDisabled() throws Exception { smtpConfiguration.setHeloEhloEnforcement(false); init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(smtpProtocol1.isConnected()) .as("first connection taken") .isTrue(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); String sender1 = "mail_sender1@localhost"; smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
@Test public void testMultipleMailsAndRset() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.reset(); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.quit(); // mail was propagated by SMTPServer assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); }
@Test public void testNoRecepientSpecified() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); // left out for test smtpProtocol.rcpt(new Address("mail@localhost")); smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testNoRecepientSpecified\r\n"); assertThat(SMTPReply.isNegativePermanent(smtpProtocol.getReplyCode())) .as("sending succeeded without recepient") .isTrue(); smtpProtocol.quit(); // mail was propagated by SMTPServer assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); }
@Test public void testSimpleMailSendWithHELO() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); smtpProtocol.helo(InetAddress.getLocalHost().toString()); smtpProtocol.setSender("mail@localhost"); smtpProtocol.addRecipient("mail@localhost"); smtpProtocol.sendShortMessageData("Subject: test mail\r\n\r\nTest body testSimpleMailSendWithHELO\r\n.\r\n"); smtpProtocol.quit(); smtpProtocol.disconnect(); // mail was propagated by SMTPServer assertThat(queue.getLastMail()) .as("mail received by mail server") .isNotNull(); }
client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect();
@Test public void testReceivedHeader() throws Exception { init(smtpConfiguration); SMTPClient smtp = newSMTPClient(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull();; smtp.helo(InetAddress.getLocalHost().toString()); smtp.setSender("mail@localhost"); smtp.addRecipient("mail@localhost"); smtp.sendShortMessageData("Subject: test\r\n\r\n"); smtp.quit(); smtp.disconnect(); assertThat(queue.getLastMail().getMessage().getHeader("Received")) .as("spooled mail has Received header") .isNotNull(); }
@Ignore @Test public void testEmptyMessageReceivedHeader() throws Exception { init(smtpConfiguration); SMTPClient smtp = newSMTPClient(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull();; smtp.helo(InetAddress.getLocalHost().toString()); smtp.setSender("mail@localhost"); smtp.addRecipient("mail@localhost"); smtp.sendShortMessageData(""); smtp.quit(); smtp.disconnect(); assertThat(queue.getLastMail().getMessage().getHeader("Received")) .as("spooled mail has Received header") .isNotNull(); // TODO: test body size }