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

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

Introduction

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

Prototype

public boolean completePendingCommand() throws IOException 

Source Link

Document

At least one SMTPClient method ( #sendMessageData sendMessageData ) does not complete the entire sequence of SMTP commands to complete a transaction.

Usage

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

public void testHandleMessageSizeLimitExceeded() throws Exception {
    smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    init(smtpConfiguration);/*from  ww  w.ja  va 2  s  .co m*/

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

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

    smtpProtocol.setSender("mail@localhost");
    smtpProtocol.addRecipient("mail@localhost");

    Writer wr = smtpProtocol.sendMessageData();
    // create Body with more than 1kb . 502
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100\r\n");
    // second line
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write("123456781012345678201\r\n"); // 521 + CRLF = 523 + 502 => 1025
    wr.close();

    assertFalse(smtpProtocol.completePendingCommand());

    assertEquals("expected 552 error", 552, smtpProtocol.getReplyCode());

}

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

@Test
public void testHandleMessageSizeLimitRespected() throws Exception {
    smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    init(smtpConfiguration);// w  w w. j a va2 s  .c  om

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

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

    smtpProtocol.setSender("mail@localhost");
    smtpProtocol.addRecipient("mail@localhost");

    Writer wr = smtpProtocol.sendMessageData();
    // create Body with less than 1kb
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write(
            "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
    wr.write("1234567810123456782012\r\n"); // 1022 + CRLF = 1024
    wr.close();

    assertTrue(smtpProtocol.completePendingCommand());

    assertEquals("expected 250 ok", 250, smtpProtocol.getReplyCode());

}