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

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

Introduction

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

Prototype

public boolean isConnected() 

Source Link

Document

Returns true if the client is currently connected to a server.

Usage

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

@Test
public void testMaxRcpt() throws Exception {
    smtpConfiguration.setMaxRcpt(1);//from ww w.  j a v a 2s . co m
    init(smtpConfiguration);

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

    assertTrue("first connection taken", smtpProtocol1.isConnected());

    // no message there, yet
    assertNull("no mail received by mail server", queue.getLastMail());

    smtpProtocol1.helo(InetAddress.getLocalHost().toString());

    String sender1 = "mail_sender1@james.apache.org";
    String rcpt1 = "test@localhost";
    String rcpt2 = "test2@localhost";

    smtpProtocol1.setSender(sender1);
    smtpProtocol1.addRecipient(rcpt1);

    smtpProtocol1.addRecipient(rcpt2);
    assertEquals("expected 452 error", 452, smtpProtocol1.getReplyCode());

    smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body testMaxRcpt1\r\n");

    // After the data is send the rcpt count is set back to 0.. So a new
    // mail with rcpt should be accepted

    smtpProtocol1.setSender(sender1);

    smtpProtocol1.addRecipient(rcpt1);

    smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body testMaxRcpt2\r\n");

    smtpProtocol1.quit();

}

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

@Test
public void testReverseEqualsEhlo() throws Exception {
    smtpConfiguration.setReverseEqualsEhlo();
    smtpConfiguration.setAuthorizedAddresses("192.168.0.1");
    // temporary alter the loopback resolution
    InetAddress jamesDomain = null;
    try {/*from w  w w.j  a v  a 2s.  co m*/
        jamesDomain = dnsServer.getByName("james.apache.org");
    } catch (UnknownHostException e) {
        fail("james.apache.org currently cannot be resolved (check your DNS/internet connection/proxy settings to make test pass)");
    }
    dnsServer.setLocalhostByName(jamesDomain);
    try {
        init(smtpConfiguration);

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

        assertTrue("first connection taken", smtpProtocol1.isConnected());

        // no message there, yet
        assertNull("no mail received by mail server", queue.getLastMail());

        String ehlo1 = "abgsfe3rsf.de";
        String ehlo2 = "james.apache.org";
        String mail = "sender";
        String rcpt = "recipient";

        smtpProtocol1.sendCommand("ehlo", ehlo1);
        smtpProtocol1.setSender(mail);
        smtpProtocol1.addRecipient(rcpt);

        // this should give a 501 code cause the ehlo not equals reverse of
        // ip
        assertEquals("expected error: ehlo not equals reverse of ip", 501, smtpProtocol1.getReplyCode());

        smtpProtocol1.sendCommand("ehlo", ehlo2);
        smtpProtocol1.setSender(mail);
        smtpProtocol1.addRecipient(rcpt);

        // ehlo is resolvable. so this should give a 250 code
        assertEquals("ehlo accepted", 250, smtpProtocol1.getReplyCode());

        smtpProtocol1.quit();
    } finally {
        dnsServer.setLocalhostByName(null);
    }
}

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

@Test
public void testHeloEnforcement() throws Exception {
    init(smtpConfiguration);/*from ww w  .  ja va2s .  com*/

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

    assertTrue("first connection taken", smtpProtocol1.isConnected());

    // no message there, yet
    assertNull("no mail received by mail server", queue.getLastMail());

    String sender1 = "mail_sender1@localhost";
    smtpProtocol1.setSender(sender1);
    assertEquals("expected 503 error", 503, smtpProtocol1.getReplyCode());

    smtpProtocol1.helo(InetAddress.getLocalHost().toString());

    smtpProtocol1.setSender(sender1);

    smtpProtocol1.quit();
}

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

@Test
public void testHeloEnforcementDisabled() throws Exception {
    smtpConfiguration.setHeloEhloEnforcement(false);
    init(smtpConfiguration);/*from  w  ww .  ja v a  2s  . com*/

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

    assertTrue("first connection taken", smtpProtocol1.isConnected());

    // no message there, yet
    assertNull("no mail received by mail server", queue.getLastMail());

    String sender1 = "mail_sender1@localhost";

    smtpProtocol1.setSender(sender1);

    smtpProtocol1.quit();
}