greenmail is a free, open source api development & testing project written in Java and released under Apache-2.0. It has 744 GitHub stars, 204 forks and 67 open issues, and was last pushed 13 hours ago. On this registry it ranks #95 of 103 tracked projects in API Development & Testing, with 5 head-to-head comparisons available.

What is greenmail?

What it is

GreenMail is a Java project that provides a virtual mail server for testing email-based applications, services, and systems. It is Apache-2.0 licensed, published through Maven Central as com.icegreen:greenmail, and listed in Developer Tools / API Development & Testing.

It solves the problem of testing email without a live mail server. Developers can send, receive, and verify email by embedding GreenMail in a unit test or running it as a standalone container. The project supports SMTP, IMAP, and POP3, and its topics describe it as a mock-server and integration-testing tool.

Key capabilities

  • GreenMail acts as a virtual, mocking, or sandbox mail server, so tests can exercise mail protocols without a live mail system.
  • It supports SMTP, IMAP, and POP3, the common mail protocols named in the README and topics.
  • Developers can send, receive, and verify emails, which provides direct test-facing functionality.
  • GreenMail can be embedded in a unit test, allowing Java tests to use the mail server inside the test process.
  • GreenMail can run as a standalone container, which fits tests that need a separate mail service.
  • The README documents version compatibility with JakartaMail and frameworks such as Jakarta EE, Spring, and Apache commons-mail.

Who uses it and how

  • Java developers use GreenMail in integration tests when an application must produce or consume email through SMTP, IMAP, or POP3 without a real mail provider.
  • Test authors embed GreenMail in unit tests to send, receive, and verify email during automated tests.
  • Teams run GreenMail as a standalone container when the mail server should be separate from the application under test.
  • The separate GreenMail Client Integrations project provides a containerized example integration with various web mail clients.

Getting started

Typical use adds com.icegreen:greenmail as a Maven dependency, or runs the greenmail/standalone Docker image shown by the README badge. Source builds use mvn clean install -Pdocker with Maven Wrapper, Maven 3.9.x or higher, and JDK 11 or newer; omitting -Pdocker skips the Docker image build.

When to use it — and when not to

GreenMail fits Java tests that need a mock SMTP, IMAP, and POP3 server without a live mail provider. It is less suitable when a production mail server is required, because the README presents GreenMail as a virtual mail server for testing. The documented self-hosted path is mainly the standalone container; the README does not list database, storage, or SMTP provider dependencies, but users must select the matching JakartaMail and framework version.

project readme (upstream, from github) — read inline

GreenMail

Build status Maven Central StackOverflow Docker Pulls javadoc

GreenMail allows developers to test email-based applications, services or systems without access to a live mail server. Developers can send, receive, and verify emails by embedding GreenMail in a unit test or running it as a standalone container. GreenMail acts as a virtual (mocking/sandbox) mail server and supports common mail protocols SMTP, IMAP and POP3.

The separate GreenMail Client Integrations project provides a containerized example integration of GreenMail with various web mail clients.

The GreenMail project welcomes any contribution, so go ahead and fork/open a pull request! See the guidelines below.

Version compatibility

GreenMail Mail API Example frameworks
2.1.x JakartaMail 2.1.x Jakarta EE 10
2.0.x JakartaMail 2.0.x Jakarta EE 9, Spring 6,
1.6.x JakartaMail 1.6.x Jakarta EE 8, Spring 5, Apache commons-mail 1.6, ...

Development

  • Build GreenMail from source

    mvn clean install -Pdocker

    This project uses Maven Wrapper for consistent build using Maven 3.9.x or higher, and requires JDK 11 or newer for building.

    • Skip building the docker image by leaving out the -Pdocker profile option
    • Skip long-running integration tests using the Maven option -DskipITs
  • Build the Maven site (and the optional example report)

    mvn site -Psite

  • Build and deploy a release

    For rolling a release including version increment and release upload, do

    mvn clean release:prepare -Prelease,docker,docker-tag-latest mvn release:perform -Prelease,docker,docker-tag-latest

    For a tagged release and deployment to Sonatype OpenSource Repository Hosting and later syncing to Maven Central, do

    mvn clean deploy -Prelease,release-ossrh,docker,docker-tag-latest

    Note: Do only use docker-tag-latest profile if you really want the tag latest, e.g. for newest release of the highest version.

  • Build and deploy a snapshot

    For a Maven Snapshot deployment to Sonatype, do

    mvn clean deploy -Prelease-ossrh,docker

Roadmap

  • 2.1
    • Baseline: Jakarta EE 10
      • JakartaMail 2.1 / Angus Mail
      • Java 11
      • Jersey 3.1.x
    • Only junit 5?
  • 2.0 (branch master)
    • Baseline: Jakarta EE 9
      • JakartaMail 2.0
      • Jersey 3.0.x for servlet 5 / restfulWS-3.0
      • Java 11 for building / running integration tests
    • Java 8
    • Deprecations (no GreenMailRule in greenmail-core, ...)
  • 1.6 (branch releases/1.6.x)
    • Bugfix and maintenance

Contributing

We really appreciate your contribution!

Please check out the contributing guide.

Misc

Many thanks to JProfiler and Jetbrains for supporting this project with free OSS licenses

Frequently asked questions

Is greenmail free to use?

greenmail is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does greenmail do?

Official master for the Greenmail project

What is greenmail written in?

greenmail is primarily written in Java. Its source is publicly available at https://github.com/greenmail-mail-test/greenmail, and it has 744 GitHub stars.