Greenmail maven repository

GreenMail is a popular open-source library used for testing email functionality in Java applications. It provides a simple and flexible way to send and receive emails, making it an essential tool for testing email-based features in your application.

To use GreenMail in your Maven-based project, you'll need to add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.icegreen</groupId>
    <artifactId>greenmail</artifactId>
    <version>1.6.6</version>
    <scope>test</scope>
</dependency>

You can adjust the version number to match the one you need.

Here's a brief overview of how to use GreenMail:

  1. Create a GreenMail instance: You'll need to create an instance of the GreenMail class, which will manage the email server and provide a way to send and receive emails.
GreenMail greenMail = new GreenMail();
  1. Start the email server: Before you can send or receive emails, you'll need to start the email server. You can do this by calling the start() method on the GreenMail instance.
greenMail.start();
  1. Send an email: To send an email, you'll need to create a SimpleMail object and set its properties (e.g., sender, recipient, subject, body). Then, you can use the send() method to send the email.
SimpleMail mail = new SimpleMail("[email protected]", "[email protected]", "Subject", "Body");
greenMail.send(mail);
  1. Receive an email: To receive an email, you can use the receive() method on the GreenMail instance. This method will block until an email is received, and then return the email.
SimpleMail receivedMail = greenMail.receive();
  1. Stop the email server: When you're finished with the email server, you can stop it by calling the stop() method on the GreenMail instance.
greenMail.stop();

That's a basic overview of how to use GreenMail in your Maven-based project. You can find more detailed documentation and examples on the GreenMail website.