Examples of SmartClient


Examples of org.subethamail.smtp.client.SmartClient

    SMTPServer smtpServer = new SMTPServer(handlerFactory);
    smtpServer.setPort(0);
    smtpServer.start();
    try
    {
      SmartClient client = new SmartClient("localhost", smtpServer.getPort(), "test-client.example.org");
      client.from("john@exmaple.com");
      client.to("jane@example.org");
      client.quit();
    }
    finally
    {
      smtpServer.stop();
    }
View Full Code Here

Examples of org.subethamail.smtp.client.SmartClient

        wiser.stop();
    }

    @Test
    public void testQuit() throws Exception {
        SmartClient smartClient = new SmartClient("localhost", 25, "localhost");
        smartClient.from("");
        smartClient.to("postmaster@example.org");
        smartClient.dataStart();
        byte[] bytes = ExampleMailData.simple().bytes;
        smartClient.dataWrite(bytes, bytes.length);
        smartClient.dataEnd();
        smartClient.quit();

        assertTrue(quitReceived);
        assertEquals(1, wiser.getMessages().size());
    }
View Full Code Here

Examples of org.subethamail.smtp.client.SmartClient

     */
    public void transmit(Mail mail, InetAddress inetAddress)
            throws SendException, RecipientsWereRejectedException,
            PostponeException {
        this.mail = mail;
        SmartClient smartClient = null;
        try {
            outgoingConnectionsRegistry.openConnection(inetAddress);
        } catch (PostponeException e) {
            e.setRemoteMta(remoteMta);
            throw e;
        }
        try {
            smartClient = clientFactory.create(inetAddress);
            smartClient.from(mail.from.getSmtpText());
            List<RecipientRejection> recipientRejections =
                    new ArrayList<RecipientRejection>();
            List<Recipient> acceptedRecipients = new ArrayList<Recipient>();
            for (Recipient recipient : mail.recipients) {
                try {
                    smartClient.to(recipient.sourceRouteStripped());
                    acceptedRecipients.add(recipient);
                } catch (SMTPException e) {
                    RemoteMtaErrorResponseException sendException =
                            new RemoteMtaErrorResponseException(e, remoteMta);
                    recipientRejections.add(new RecipientRejection(recipient,
                            sendException));
                    String logId = logIdFactory.next();
                    sendException.initLogId(logId);
                    logger.debug("Recipient " + recipient
                            + " was rejected/failed. Log-ID=" + logId
                            + ". Continuing with the next recipient if one "
                            + "exists. " + e.getResponse());
                }
            }
            if (acceptedRecipients.isEmpty()) {
                logger.debug("All recipients were rejected");
                throw new RecipientsWereRejectedException(recipientRejections);
            }
            smartClient.dataStart();
            writeDataTo(smartClient);
            smartClient.dataEnd();
            if (!recipientRejections.isEmpty())
                throw new RecipientsWereRejectedException(recipientRejections);
            else
                return;
        } catch (SMTPException e) {
            throw new RemoteMtaErrorResponseException(e, remoteMta);
        } catch (UnknownHostException e) {
            // impossible
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new SendException("Connection failed: " + e.toString(), e,
                    new EnhancedStatus(450, "4.4.0",
                            "No answer from host or bad connection"), remoteMta);
        } finally {
            if (smartClient != null) {
                smartClient.quit();
            }
            outgoingConnectionsRegistry.releaseConnection(inetAddress);
        }
    }
View Full Code Here

Examples of org.subethamail.smtp.client.SmartClient

    public SmartClient create(InetAddress inetAddress, int port)
            throws UnknownHostException, SMTPException, IOException {
        SocketAddress bindpoint =
                bind == null ? null : new InetSocketAddress(bind, 0);

        return new SmartClient(inetAddress.getHostAddress(), port, bindpoint,
                helo);
    }
View Full Code Here

Examples of org.subethamail.smtp.client.SmartClient

    }

    @Test
    public void testReceivingAndSending() throws IOException, SMTPException,
            IOException {
        SmartClient client = new SmartClient("localhost", 8025, "SmartClient");
        client.from("john@example.com");
        client.to("jane@example.com");
        client.dataStart();
        byte[] exampleMail = ExampleMailData.simple().bytes;
        client.dataWrite(exampleMail, exampleMail.length);
        client.dataEnd();
        client.quit();

        WiserMessage message = wiser.getMessages().get(0);
        assertThat(message.getData(), new ArrayEndsWith(exampleMail));
    }
View Full Code Here

Examples of org.subethamail.smtp.client.SmartClient

        retrieveMail();
    }

    private void sendMail() throws UnknownHostException, IOException,
            SMTPException {
        SmartClient client =
                new SmartClient("localhost", PORT_SMTP, "SmartClient");
        client.from("jane@example.com");
        client.to("john@example.com");
        client.dataStart();
        byte[] exampleMail = ExampleMailData.simple().bytes;
        client.dataWrite(exampleMail, exampleMail.length);
        client.dataEnd();
        client.quit();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.