Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with a Java Mail Server for Testing

I'm in the process of testing an application that takes mail out of a mailbox, performs some action based on the content of that mail, and then sends a response mail depending on the result of the action.

I'm looking for a way to write tests for this application. Ideally, I'd like for these tests to bring up their own mail server, push my test emails to a folder on this mail server, and have my application scrape the mail out of the mail server that my test started.

Configuring the application to use the mailserver is not difficult, but I do not know where to look for a programatic way of starting a mail server in Java. I've looked at JAMES, but I am unable to figure out how to start the server from within my test.

So the question is this: What can I use for a mail server in Java that I can configure and start entirely within Java?

like image 685
Charles Dimino Avatar asked May 06 '10 16:05

Charles Dimino


2 Answers

There is also very simple in use GreenMail which was designer as a mail server for automatic "unit" tests.

From projects web page (probably there are some others tools with sending/receiving functionality nowadays):

GreenMail is an open source, intuitive and easy-to-use test suite of email servers for testing purposes. Supports SMTP, POP3, IMAP with SSL socket support. GreenMail also provides a JBoss GreenMail Service. GreenMail is the fist and only library that offers a test framework for both receiving and retrieving emails from Java.

like image 111
Marcin Zajączkowski Avatar answered Oct 01 '22 04:10

Marcin Zajączkowski


I've used both Dumbster and SubEthaSmtp in unit tests before to test code that sends email.

I found Dumbster to be far easier to work with.

like image 25
matt b Avatar answered Oct 01 '22 03:10

matt b