GreenMail 1.3 / 1.3.1 Beta

An open source, intuitive and easy-to-use test suite of email servers for testing purposes
GreenMail is an open source, intuitive and easy-to-use test suite of email servers for testing purposes.

The GreenMail project supports SMTP, POP3, IMAP with SSL socket support. It 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.

GreenMail is useful in the following scenarios:

Test Your Sending Code

System testing an application. GreenMail responds like a regular SMTP server but does not deliver any email, which enables it to be used in real life applications and real test cases. Messages can easily be extracted, verified, and modified. Support for SMTPS (SSL) is enabled.

GreenMail is an excellent choice for unit testing code that needs to send email with a succinct, efficient (non-polling) way to wait for messages to arrive, retrieve, verify, and modify messages.

Note that retrieval of emails can be made with a simple java method or through a provided POP3, IMAP retriever helper class.

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

Again GreenMail can be used for system or unit testing an application needing to use POP3 or IMAP by responding like a standard compliant POP3 or IMAP server. Support for POP3S and IMAPS (SSL) is also enabled.
Messages can be placed directly in users mailboxes or by using SMTP.
GreenMail ships with helper classes for sending and retrieving. See the javadocs for the Retriever.java class

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 Retrieving

GreenMail 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 environment

GreenMail 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).

Implementation

The implementation is in 100% Java with only a few library dependencies:

- javamail.jar - JavaMail API
- activation.jar - Java Activation Framework, required by JavaMail
- slf4j-api.jar - required for logging via Simple Logging Facade for Java

last updated on:
May 28th, 2009, 23:28 GMT
price:
FREE!
developed by:
Icegreen Technologies
license type:
The Apache License 2.0 
category:
ROOT \ Communications \ Email

FREE!

In a hurry? Add it to your Download Basket!

user rating 15

UNRATED
2.2/5
 

0/5

1 Screenshot
GreenMail
What's New in version 1.3.1 Beta
  • Better "Bind Address Exception" handling. GreenMail now will try opening the server port multiple times with time delays.
  • GreenMail now open server ports on "0.0.0.0" if bind address is specified as null
  • GreenMail now have a "catch-all" retriever helper. See GreenMail.getReceviedMessagesForDomain(String domain)
  • Changes: For the jboss-service - More verbose startup info message including mail server hostname, protocols and ports
read full changelog

Add your review!

SUBMIT