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

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

Introduction

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

Prototype

public int mail(String reversePath) throws IOException 

Source Link

Document

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

Usage

From source file:org.apache.james.protocols.lmtp.AbstractLMTPServerTest.java

@Override
public void testMailWithoutBrackets() throws Exception {
    TestMessageHook hook = new TestMessageHook();
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

    ProtocolServer server = null;// www.  j a v a 2  s  .  co m
    try {
        server = createServer(createProtocol(hook), address);
        server.bind();

        SMTPClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.helo("localhost");
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.mail(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.quit();
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
        client.disconnect();

        Iterator<MailEnvelope> queued = hook.getQueued().iterator();
        assertFalse(queued.hasNext());

    } finally {
        if (server != null) {
            server.unbind();
        }
    }

}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testMailWithoutBrackets() throws Exception {
    TestMessageHook hook = new TestMessageHook();
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

    ProtocolServer server = null;//from  w  w w . ja v  a  2s .c o  m
    try {
        server = createServer(createProtocol(hook), address);
        server.bind();

        SMTPClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.helo("localhost");
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.mail("invalid");
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isNegativePermanent(client.getReplyCode()));

        client.addRecipient(RCPT1);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isNegativePermanent(client.getReplyCode()));

        client.quit();
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
        client.disconnect();

        Iterator<MailEnvelope> queued = hook.getQueued().iterator();
        assertFalse(queued.hasNext());

    } finally {
        if (server != null) {
            server.unbind();
        }
    }

}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testInvalidNoBracketsEnformance() throws Exception {
    TestMessageHook hook = new TestMessageHook();
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

    ProtocolServer server = null;/*from  ww  w  .j  ava 2s . c om*/
    try {
        Protocol protocol = createProtocol(hook);
        ((SMTPConfigurationImpl) protocol.getConfiguration()).setUseAddressBracketsEnforcement(false);
        server = createServer(protocol, address);
        server.bind();

        SMTPClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.helo("localhost");
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.mail(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.addRecipient(RCPT1);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.quit();
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
        client.disconnect();

        Iterator<MailEnvelope> queued = hook.getQueued().iterator();
        assertFalse(queued.hasNext());

    } finally {
        if (server != null) {
            server.unbind();
        }
    }

}