The Dumbster is a very simple fake SMTP server designed for unit and system testing applications that send email messages. It responds to all standard SMTP commands but does not deliver messages to the user. The messages are stored within the Dumbster for later extraction and verification.
This repository is a fork of https://github.com/kirviq/dumbster.
Differences:
- Added a possibility to attach a listener on messages arriving
- Add support for multipart messages (patch created by koke24)
- Remove lombok
- Make SmtpMessage Json serializable and deserializable
Aside from that, the actual smtp logic is completely unchanged.
Add maven dependency:
<dependency>
<groupId>se.alipsa</groupId>
<artifactId>dumbster</artifactId>
<version>1.7.2</version>
<scope>test</scope>
</dependency>
Start testing:
class SomeTest {
public void runTest() {
try (SimpleSmtpServer dumbster = SimpleSmtpServer.start(SimpleSmtpServer.AUTO_SMTP_PORT)) {
sendMessage(dumbster.getPort(), "[email protected]", "Test", "Test Body", "[email protected]");
List<SmtpMessage> emails = dumbster.getReceivedEmails();
assertThat(emails, hasSize(1));
SmtpMessage email = emails.get(0);
assertThat(email.getHeaderValue("Subject"), is("Test"));
assertThat(email.getBody(), is("Test Body"));
assertThat(email.getHeaderValue("To"), is("[email protected]"));
}
}
}
See more examples in the included unit tests.