Easy to useGreenMail 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. ScenariosGreenMail is useful in the following scenarios:Test Your Sending Code
public void testYourSendingCode() throws Exception { GreenMail greenMail = new GreenMail(); //uses test ports by default greenMail.start(); GreenMailUtil.sendTextEmailTest("to@localhost.com", "from@localhost.com", "subject", "body"); //replace this with your send code assertEquals("body", GreenMailUtil.getBody(greenMail.getReceivedMessages()[0])); greenMail.stop(); //That's it! } Test Your Retrieving Code
public void testYourRetrievingCode() throws Exception { GreenMail greenMail = new GreenMail(); //uses test ports by default greenMail.start(); MimeMessage message = <CONSTRUCT MESSAGE > User user = greenMail.setUser("to@localhost.com", "login-id", "password"); user.deliver(message); GreenMailUtil.sendTextEmailTest("to@localhost.com", "from@localhost.com", subject, body); assertEquals(2, greenMail.getReceivedMessages().length); <PLACE YOUR POP3/IMAP RETRIVE CODE HERE> } Sending and RetrievingGreenMail can easily be configured to use all or a combination of ports, protocols, and bind addresses. For example it’s possible to run GreenMail on SMTP, POP3, POP3S and IMAPS ports as easily as only SMTP. Many systems might already be running these servers or don’t allow non root users to open the default ports which is why GreenMail ships with a special configuration for testing.Mocking a mail server for your development environmentGreenMail provides a JBoss GreenMail service for mocking a mail server for development. It safes you the overhead of either installing a full productive server (like Apache James or JBoss Mail).ImplementationThe implementation is in 100% Java with only a few library dependencies:
Source CodeGreenMail is open source released under The Apache 2.0 License. Binaries and source can be downloaded here on Sourceforge.GreenMail's protocol source code is based on a cocktail of Foedus and James. |