Example usage for org.apache.commons.net.smtp SMTPClient reset

List of usage examples for org.apache.commons.net.smtp SMTPClient reset

Introduction

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

Prototype

public boolean reset() throws IOException 

Source Link

Document

Aborts the current mail transaction, resetting all server stored sender, recipient, and mail data, cleaing all buffers and tables.

Usage

From source file:me.schiz.jmeter.protocol.smtp.sampler.SMTPSampler.java

private SampleResult sampleReset(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    SMTPClient client = null;
    if (soclient instanceof SMTPClient)
        client = (SMTPClient) soclient;//from   w ww .j  a va 2 s . c  o  m

    String request = "COMMAND\n";
    request += "Client : " + getClient() + "\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        sr.setResponseCode("404");
        sr.setResponseData(("Client `" + getClient() + "` not found").getBytes());
        sr.setSuccessful(false);
        return sr;
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                sr.setSuccessful(client.reset());
                sr.setResponseCode(String.valueOf(client.getReplyCode()));
                sr.setResponseData(client.getReplyString().getBytes());
                setSuccessfulByResponseCode(sr, client.getReplyCode());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + client + "` ", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}

From source file:org.apache.james.smtpserver.SMTPServerTest.java

@Test
public void testMultipleMailsAndRset() throws Exception {
    init(smtpConfiguration);//from  w  w w .  jav a 2s  .c om

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", smtpListenerPort);

    smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());

    smtpProtocol.setSender("mail@sample.com");

    smtpProtocol.reset();

    smtpProtocol.setSender("mail@sample.com");

    smtpProtocol.quit();

    // mail was propagated by SMTPServer
    assertNull("no mail received by mail server", queue.getLastMail());
}