/*** * 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()); }
InvalidKeyException, InvalidKeySpecException if (!SMTPReply.isPositiveIntermediate(sendCommand(SMTPCommand.AUTH, AUTH_METHOD.getAuthName(method)))) { return false; return SMTPReply.isPositiveCompletion(sendCommand( Base64.encodeBase64StringUnChunked(("\000" + username + "\000" + password).getBytes(getCharset())) )); System.arraycopy(hmacResult, 0, toEncode, usernameBytes.length + 1, hmacResult.length); return SMTPReply.isPositiveCompletion(sendCommand( Base64.encodeBase64StringUnChunked(toEncode))); if (!SMTPReply.isPositiveIntermediate(sendCommand( Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))))) { return false; return SMTPReply.isPositiveCompletion(sendCommand( Base64.encodeBase64StringUnChunked(password.getBytes(getCharset())))); return SMTPReply.isPositiveIntermediate(sendCommand( Base64.encodeBase64StringUnChunked(username.getBytes(getCharset())) ));
@Test public void testStartTlsNotSupported() throws Exception { TestMessageHook hook = new TestMessageHook(); ProtocolServer server = null; try { server = createServer(createProtocol(hook)); server.bind(); SMTPClient client = createClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.sendCommand("STARTTLS"); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertThat(queued.hasNext()).isFalse(); } finally { if (server != null) { server.unbind(); } } }
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isNegativeTransient(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect();
if (!SMTPReply.isPositiveIntermediate(data())) { return null;
@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(); }
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isNegativeTransient(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
@Test public void testUnknownCommand() throws Exception { TestMessageHook hook = new TestMessageHook(); ProtocolServer server = null; try { server = createServer(createProtocol(hook)); server.bind(); SMTPClient client = createClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.sendCommand("UNKNOWN"); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertThat(queued.hasNext()).isFalse(); } finally { if (server != null) { server.unbind(); } } }
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isNegativeTransient(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect();
if (!SMTPReply.isPositiveIntermediate(data())) return null;
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isNegativeTransient(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
/*** * Sends a NOOP command to the SMTP server. This is useful for preventing * server timeouts. * <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 sendNoOp() throws IOException { return SMTPReply.isPositiveCompletion(noop()); }
@Test public void testStartTlsNotSupported() throws Exception { TestMessageHook hook = new TestMessageHook(); ProtocolServer server = null; try { server = createServer(createProtocol(hook)); server.bind(); SMTPClient client = createClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.sendCommand("STARTTLS"); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertThat(queued.hasNext()).isFalse(); } finally { if (server != null) { server.unbind(); } } }
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isNegativeTransient(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect();
if (!SMTPReply.isPositiveIntermediate(data())) return null;
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
/*** * Aborts the current mail transaction, resetting all server stored * sender, recipient, and mail data, cleaing all buffers and tables. * <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 reset() throws IOException { return SMTPReply.isPositiveCompletion(rset()); }
@Test public void testEhloNotSupported() throws Exception { TestMessageHook hook = new TestMessageHook(); ProtocolServer server = null; try { server = createServer(createProtocol(hook)); server.bind(); SMTPClient client = createClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.sendCommand("HELO localhost"); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).describedAs("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertThat(queued.hasNext()).isFalse(); } finally { if (server != null) { server.unbind(); } } }
InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isNegativeTransient(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect();