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

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

Introduction

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

Prototype

public int helo(String hostname) throws IOException 

Source Link

Document

A convenience method to send the SMTP HELO command to the server, receive the reply, and return the reply code.

Usage

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

@Test
public void testSenderDomainResolvRelayClient() throws Exception {
    smtpConfiguration.setSenderDomainResolv();
    smtpConfiguration.setCheckAuthNetworks(true);
    init(smtpConfiguration);/*w  ww. j a v a  2 s.c  o  m*/

    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@xfwrqqfgfe.de";
    String sender2 = "mail_sender2@james.apache.org";

    smtpProtocol1.setSender(sender1);
    assertEquals("expected 501 error", 501, smtpProtocol1.getReplyCode());

    smtpProtocol1.setSender(sender2);

    smtpProtocol1.quit();

}

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

@Test
public void testMaxRcpt() throws Exception {
    smtpConfiguration.setMaxRcpt(1);//from w  ww. j a  v a 2s.com
    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 testMaxRcptDefault() throws Exception {
    init(smtpConfiguration);/*from   ww  w  . j a  v  a 2  s  .c  o m*/

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

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

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

    smtpProtocol1.setSender(sender1);

    smtpProtocol1.addRecipient(rcpt1);

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

    smtpProtocol1.quit();
}

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

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

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