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

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

Introduction

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

Prototype

public int rcpt(String forwardPath) throws IOException 

Source Link

Document

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

Usage

From source file:org.apache.james.jmap.VacationRelayIntegrationTest.java

@Test
public void forwardingAnEmailShouldWork() throws Exception {
    jmapGuiceProbe.modifyVacation(AccountId.fromString(USER_WITH_DOMAIN),
            VacationPatch.builder().isEnabled(true).textBody(REASON).build());

    String externalMail = "ray@yopmail.com";

    SMTPClient smtpClient = new SMTPClient();
    smtpClient.connect(LOCALHOST_IP, SMTP_PORT);
    smtpClient.helo(DOMAIN);/*  w ww. jav  a 2s  .  c o m*/
    smtpClient.setSender(externalMail);
    smtpClient.rcpt("<" + USER_WITH_DOMAIN + ">");
    smtpClient.sendShortMessageData("content");

    calmlyAwait.atMost(1, TimeUnit.MINUTES).until(() -> {
        try {
            when().get("/api/email").then().statusCode(200).body("[0].from", equalTo(USER_WITH_DOMAIN))
                    .body("[0].to[0]", equalTo(externalMail)).body("[0].text", equalTo(REASON));

            return true;
        } catch (AssertionError e) {
            return false;
        }
    });
}

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

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

    ProtocolServer server = null;// ww  w.j av a 2 s .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.setSender(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

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

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

@Test
public void testRcptWithoutBrackets() 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 a2 s  .  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.setSender(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

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

}