Example usage for org.apache.commons.net.smtp SMTPSClient getReplyStrings

List of usage examples for org.apache.commons.net.smtp SMTPSClient getReplyStrings

Introduction

In this page you can find the example usage for org.apache.commons.net.smtp SMTPSClient getReplyStrings.

Prototype

public String[] getReplyStrings() 

Source Link

Document

Returns the lines of text from the last SMTP server response as an array of strings, one entry per line.

Usage

From source file:org.apache.james.protocols.smtp.AbstractStartTlsSMTPServerTest.java

@Test
public void testStartTLS() throws Exception {
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

    ProtocolServer server = null;// ww w.j  a v  a  2 s.  c  om
    try {
        server = createServer(createProtocol(new ProtocolHandler[0]), address,
                Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
        server.bind();

        SMTPSClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.sendCommand("EHLO localhost");
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        boolean startTLSAnnounced = false;
        for (String reply : client.getReplyStrings()) {
            if (reply.toUpperCase(Locale.UK).endsWith("STARTTLS")) {
                startTLSAnnounced = true;
                break;
            }
        }
        assertTrue(startTLSAnnounced);

        assertTrue(client.execTLS());

        // TODO: Add back once commons-net 3.1.0 was released.
        // See: NET-421
        //
        //client.quit();
        //assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.disconnect();

    } finally {
        if (server != null) {
            server.unbind();
        }
    }

}