Package com.icegreen.greenmail.util
Class GreenMailProxy
java.lang.Object
com.icegreen.greenmail.configuration.ConfiguredGreenMail
com.icegreen.greenmail.util.GreenMailProxy
- All Implemented Interfaces:
GreenMailOperations
- Direct Known Subclasses:
GreenMailRule
Proxy that routes all operations to an internal greenmail instance
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionStream<jakarta.mail.internet.MimeMessage>findReceivedMessages(Predicate<GreenMailUser> userPredicate, Predicate<jakarta.mail.internet.MimeMessage> messagePredicate) Finds all messages matching the user account and message predicate.protected abstract GreenMailgetImap()getImaps()getPop3()getPop3s()jakarta.mail.internet.MimeMessage[]jakarta.mail.internet.MimeMessage[]getReceivedMessagesForDomain(String domain) Gets all messages containing given domain.getSmtp()getSmtps()loadEmails(Path path) Loads emails from given path.voidRemove/purge all data from all mail stores (POP3/IMAP)voidreset()Restart the GreenMail server.voidsetQuotaSupported(boolean isEnabled) Toggles the IMAP quota support.Sets the password for the account linked to email.Sets the password for the account linked to email.voidsetUsers(Properties users) Sets up accounts with password based on a properties map where the key is the email/login and the value the passwordvoidstart()Start the GreenMail servervoidstop()Stop the GreenMail server.booleanwaitForIncomingEmail(int emailCount) Does the same thing asGreenMailOperations.waitForIncomingEmail(long, int)but with a default timeout of 5000msbooleanwaitForIncomingEmail(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 com.icegreen.greenmail.configuration.ConfiguredGreenMail
doConfigure, withConfigurationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.icegreen.greenmail.base.GreenMailOperations
isRunning
-
Constructor Details
-
GreenMailProxy
public GreenMailProxy()
-
-
Method Details
-
getSmtp
- Returns:
- SMTP server operated by this GreenMail instance or null if there is none
-
getImap
- Returns:
- SMTP server operated by this GreenMail instance or null if there is none
-
getPop3
- Returns:
- SMTP server operated by this GreenMail instance or null if there is none
-
getSmtps
- Returns:
- SMTP server operated by this GreenMail instance or null if there is none
-
getImaps
- Returns:
- SMTP server operated by this GreenMail instance or null if there is none
-
getPop3s
- Returns:
- SMTP server operated by this GreenMail instance or null if there is none
-
getManagers
- Returns:
- Greenmail protocol managers
-
getUserManager
- Returns:
- the user manager for
-
waitForIncomingEmail
public boolean waitForIncomingEmail(long timeout, int emailCount) Description copied from interface:GreenMailOperationsUse 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 falseemailCount- waits for these many emails to arrive before returning- Returns:
- Returns false if timeout period was reached, otherwise true.
-
waitForIncomingEmail
public boolean waitForIncomingEmail(int emailCount) Description copied from interface:GreenMailOperationsDoes the same thing asGreenMailOperations.waitForIncomingEmail(long, int)but with a default timeout of 5000ms- Parameters:
emailCount- waits for these many emails to arrive before returning- Returns:
- Returns false if timeout period was reached, otherwise true.
-
getReceivedMessages
public jakarta.mail.internet.MimeMessage[] getReceivedMessages()- Returns:
- Returns all messages in all folders for all users
GreenMailUtilhas a bunch of static helper methods to extract body text etc.
-
findReceivedMessages
public Stream<jakarta.mail.internet.MimeMessage> findReceivedMessages(Predicate<GreenMailUser> userPredicate, Predicate<jakarta.mail.internet.MimeMessage> messagePredicate) Description copied from interface:GreenMailOperationsFinds all messages matching the user account and message predicate.- Parameters:
userPredicate- matches user accountsmessagePredicate- matches message- Returns:
- a stream of matching messages, matching both predicates (logical AND)
-
getReceivedMessagesForDomain
Description copied from interface:GreenMailOperationsGets all messages containing given domain.Note: This operates on the raw messages ignoring the post-box user. A CC-ed email would therefore show up multiple times for each receiving user.
- Parameters:
domain- the domain, such as 'icegreen.com' or 'some.example.com'- Returns:
- Returns all received messages for given domain.
-
setUser
Description copied from interface:GreenMailOperationsSets 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:
login- Login for which the password should be set. This is assumed to be the same as the email address.password- New password- Returns:
- the user created
-
setUser
Description copied from interface:GreenMailOperationsSets 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- Email address for which the password should be setlogin- Login name for login. This may be different to the email address. E.g. the email address could be "info@localhost", the login could be "info".password- New password- Returns:
- the user created
-
setUsers
Description copied from interface:GreenMailOperationsSets up accounts with password based on a properties map where the key is the email/login and the value the password- Parameters:
users- User/password map
-
setQuotaSupported
public void setQuotaSupported(boolean isEnabled) Description copied from interface:GreenMailOperationsToggles the IMAP quota support. Quotas are enabled by default.- Parameters:
isEnabled- true, if quotas should be supported.
-
start
public void start()Description copied from interface:GreenMailOperationsStart the GreenMail server -
stop
public void stop()Description copied from interface:GreenMailOperationsStop the GreenMail server. Clear all data (send messages, users, ...). -
reset
public void reset()Description copied from interface:GreenMailOperationsRestart the GreenMail server. Clear all data (send messages, users, ...) -
purgeEmailFromAllMailboxes
Description copied from interface:GreenMailOperationsRemove/purge all data from all mail stores (POP3/IMAP)- Throws:
FolderException- on error
-
loadEmails
Description copied from interface:GreenMailOperationsLoads emails from given path.-
Expected structure in provided path, containing EML (rfc0822) mail files
Pattern:
<EMAIL> / <FOLDER*> / <*.eml>
Example:
├── bar@localhost (directory) │ └── INBOX (directory) │ └── test-5.eml (file) └── foo@localhost (directory) └── Drafts (directory) └── draft.eml (file) - Creates user of given email if missing (by convention, with email as login and password)
- Creates intermediate mail folder if missing
- Parameters:
path- base path with email structure- Throws:
FolderException- if e.g. fails to create intermediate folderIOException- on IO error
-
Expected structure in provided path, containing EML (rfc0822) mail files
-
getGreenMail
- Returns:
- Greenmail instance provided by child class
-