Java Code Examples for org.subethamail.smtp.client.SmartClient#dataEnd()

The following examples show how to use org.subethamail.smtp.client.SmartClient#dataEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageHandlerTest.java    From subethasmtp with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompletedMailTransaction() throws Exception {

	new Expectations() {
		{
			messageHandlerFactory.create((MessageContext) any);
			result = messageHandler;

			messageHandler.from(anyString);
			messageHandler.recipient(anyString);
			messageHandler.data((InputStream) any);
			messageHandler.done();
		}
	};

	SmartClient client = new SmartClient("localhost", smtpServer.getPort(),
			"localhost");
	client.from("[email protected]");
	client.to("[email protected]");
	client.dataStart();
	client.dataWrite(TextUtils.getAsciiBytes("body"), 4);
	client.dataEnd();
	client.quit();
	smtpServer.stop(); // wait for the server to catch up
}
 
Example 2
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void writeData(SmartClient client, String resource) throws IOException {
    client.dataStart();
    InputStream is = getClass().getResourceAsStream(resource);
    if(is == null) {
        throw new FileNotFoundException("Couldn't find in classpath: "+ resource);
    }
    byte[] bytes = IOUtils.toByteArray(is);
    client.dataWrite(bytes, bytes.length);
    client.dataEnd();
}
 
Example 3
Source File: MxPopTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
private void sendMail() throws UnknownHostException, IOException,
        SMTPException {
    SmartClient client =
            new SmartClient("localhost", PORT_SMTP, "SmartClient");
    client.from("[email protected]");
    client.to("[email protected]");
    client.dataStart();
    byte[] exampleMail = ExampleMailData.simple().bytes;
    client.dataWrite(exampleMail, exampleMail.length);
    client.dataEnd();
    client.quit();
}
 
Example 4
Source File: ClientServerRelayTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
@Test
public void testReceivingAndSending() throws IOException, SMTPException,
        IOException {
    SmartClient client = new SmartClient("localhost", 8025, "SmartClient");
    client.from("[email protected]");
    client.to("[email protected]");
    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));
}
 
Example 5
Source File: RelayFunctionalTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuit() throws Exception {
    SmartClient smartClient = new SmartClient("localhost", 25, "localhost");
    smartClient.from("");
    smartClient.to("[email protected]");
    smartClient.dataStart();
    byte[] bytes = ExampleMailData.simple().bytes;
    smartClient.dataWrite(bytes, bytes.length);
    smartClient.dataEnd();
    smartClient.quit();

    assertTrue(quitReceived);
    assertEquals(1, wiser.getMessages().size());
}
 
Example 6
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void writeData(SmartClient client, String resource) throws IOException {
    client.dataStart();
    InputStream is = getClass().getResourceAsStream(resource);
    if(is == null) {
        throw new FileNotFoundException("Couldn't find in classpath: "+ resource);
    }
    byte[] bytes = IOUtils.toByteArray(is);
    client.dataWrite(bytes, bytes.length);
    client.dataEnd();
}
 
Example 7
Source File: MessageHandlerTest.java    From subethasmtp with Apache License 2.0 4 votes vote down vote up
@Test
public void testTwoMailsInOneSession() throws Exception {

	new Expectations() {
		{
			messageHandlerFactory.create((MessageContext) any);
			result = messageHandler;

			onInstance(messageHandler).from(anyString);
			onInstance(messageHandler).recipient(anyString);
			onInstance(messageHandler).data((InputStream) any);
			onInstance(messageHandler).done();

			messageHandlerFactory.create((MessageContext) any);
			result = messageHandler2;

			onInstance(messageHandler2).from(anyString);
			onInstance(messageHandler2).recipient(anyString);
			onInstance(messageHandler2).data((InputStream) any);
			onInstance(messageHandler2).done();
		}
	};

	SmartClient client = new SmartClient("localhost", smtpServer.getPort(),
			"localhost");

	client.from("[email protected]");
	client.to("[email protected]");
	client.dataStart();
	client.dataWrite(TextUtils.getAsciiBytes("body1"), 5);
	client.dataEnd();

	client.from("[email protected]");
	client.to("[email protected]");
	client.dataStart();
	client.dataWrite(TextUtils.getAsciiBytes("body2"), 5);
	client.dataEnd();

	client.quit();

	smtpServer.stop(); // wait for the server to catch up
}