com.icegreen.greenmail.util
Class GreenMail

java.lang.Object
  extended by com.icegreen.greenmail.util.GreenMail
Direct Known Subclasses:
Servers

public class GreenMail
extends Object

Since:
Jan 28, 2006
Version:
$Id: $
Author:
Wael Chatila

Constructor Summary
GreenMail()
          Creates a SMTP, SMTPS, POP3, POP3S, IMAP, and IMAPS server binding onto non-default ports.
GreenMail(ServerSetup config)
          Call this constructor if you want to run one of the email servers only
GreenMail(ServerSetup[] config)
          Call this constructor if you want to run more than one of the email servers
 
Method Summary
 ImapServer getImap()
           
 ImapServer getImaps()
           
 Managers getManagers()
           
 Pop3Server getPop3()
           
 Pop3Server getPop3s()
           
 MimeMessage[] getReceivedMessages()
           
 MimeMessage[] getReceviedMessagesForDomain(String domain)
          This method can be used as an easy 'catch-all' mechanism.
 SmtpServer getSmtp()
           
 SmtpServer getSmtps()
           
 GreenMailUser setUser(String email, String password)
          Sets the password for the account linked to email.
 GreenMailUser setUser(String email, String login, String password)
           
 void setUsers(Properties users)
          Sets up accounts with password based on a properties map where the key is the email and the value the password
 void start()
           
 void stop()
           
 GreenMailUtil util()
           
 boolean waitForIncomingEmail(int emailCount)
          Does the same thing as Object.wait(long, int) but with a timeout of 5000ms
 boolean waitForIncomingEmail(long timeout, int emailCount)
          Use this method if you are sending email in a different thread from the one you're testing from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GreenMail

public GreenMail()
Creates a SMTP, SMTPS, POP3, POP3S, IMAP, and IMAPS server binding onto non-default ports. The ports numbers are defined in ServerSetupTest


GreenMail

public GreenMail(ServerSetup config)
Call this constructor if you want to run one of the email servers only

Parameters:
config -

GreenMail

public GreenMail(ServerSetup[] config)
Call this constructor if you want to run more than one of the email servers

Parameters:
config -
Method Detail

start

public void start()

stop

public void stop()

getSmtp

public SmtpServer getSmtp()

getImap

public ImapServer getImap()

getPop3

public Pop3Server getPop3()

getSmtps

public SmtpServer getSmtps()

getImaps

public ImapServer getImaps()

getPop3s

public Pop3Server getPop3s()

getManagers

public Managers getManagers()

waitForIncomingEmail

public boolean waitForIncomingEmail(long timeout,
                                    int emailCount)
                             throws InterruptedException
Use this method if you are sending email in a different thread from the one you're testing from. Block waits for an email to arrive in any mailbox for any user. Implementation Detail: No polling wait implementation

Parameters:
timeout - maximum time in ms to wait for emailCount of messages to arrive before giving up and returning false
emailCount - waits for these many emails to arrive before returning
Returns:
Returns false if timeout period was reached, otherwise true.
Throws:
InterruptedException

waitForIncomingEmail

public boolean waitForIncomingEmail(int emailCount)
                             throws InterruptedException
Does the same thing as Object.wait(long, int) but with a timeout of 5000ms

Parameters:
emailCount -
Returns:
Throws:
InterruptedException

getReceivedMessages

public MimeMessage[] getReceivedMessages()
Returns:
Returns all messags in all folders for all users GreenMailUtil has a bunch of static helper methods to extract body text etc.

getReceviedMessagesForDomain

public MimeMessage[] getReceviedMessagesForDomain(String domain)
This method can be used as an easy 'catch-all' mechanism.

Parameters:
domain - returns all receved messages arrived to domain.

setUser

public GreenMailUser setUser(String email,
                             String password)
Sets the password for the account linked to email. If no account exits, one is automatically created when an email is received The automatically created account has the account login and password equal to the email address.

Parameters:
email -
password -

setUser

public GreenMailUser setUser(String email,
                             String login,
                             String password)

setUsers

public void setUsers(Properties users)
Sets up accounts with password based on a properties map where the key is the email and the value the password

Parameters:
users -

util

public GreenMailUtil util()