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

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

Introduction

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

Prototype

public int sendCommand(String command) throws IOException 

Source Link

Document

Sends an SMTP command with no arguments to the server, waits for a reply and returns the numerical response code.

Usage

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

@Test
public void testMultipleMailsAndRset() throws Exception {
    init(smtpConfiguration);/*from w  ww  .ja  va  2 s . 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());
}

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

@Test
public void testRelayingDenied() throws Exception {
    smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8");
    init(smtpConfiguration);//from  ww w  .  j a v  a2s. co  m

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

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

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

    smtpProtocol.addRecipient("maila@sample.com");
    assertEquals("expected 550 error", 550, smtpProtocol.getReplyCode());
}

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

@Test
public void testHandleAnnouncedMessageSizeLimitExceeded() throws Exception {
    smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    init(smtpConfiguration);/*w  ww.  ja  v  a  2s.c o  m*/

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

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

    smtpProtocol.sendCommand("MAIL FROM:<mail@localhost> SIZE=1025", null);
    assertEquals("expected error: max msg size exceeded", 552, smtpProtocol.getReplyCode());

    smtpProtocol.addRecipient("mail@localhost");
    assertEquals("expected error", 503, smtpProtocol.getReplyCode());
}

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

public void testHandleMessageSizeLimitExceeded() throws Exception {
    smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    init(smtpConfiguration);// ww w  .j a v  a2s .  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);/*from ww w .j a v  a 2  s. com*/

    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());

}