public class MailServices extends Object
Constructor and Description |
---|
MailServices(int portRangeStart,
int portRangeEnd,
String hostName) |
Modifier and Type | Method and Description |
---|---|
void |
addUser(MailUser user) |
void |
addUser(String email,
String login,
String password)
Adds a user to the mail service.
|
void |
addUser(User user)
Adds a user to the mail service.
|
String |
getHostName() |
int |
getPop3Port() |
int |
getPort(String protocol) |
javax.mail.internet.MimeMessage |
getReceivedMessage()
Get the first message of all messages received until now.
|
javax.mail.internet.MimeMessage[] |
getReceivedMessages()
Returns an array of all messages received until now.
|
int |
getSmtpPort() |
boolean |
isRunning()
Returns true if the mail servers are running.
|
void |
removeAllReceivedMessages()
Removes all received mails.
|
void |
sendMimeMessage(InputStream messageStream)
Sends an email based on a MimeMessage input stream, most likely read from a file.
|
void |
sendTextMessage(String to,
String from,
String subject,
String body)
Sends an email with the content type "text/plain" and the given contents using the test SMTP server.
|
void |
start()
Tries to start a SMTP and a POP3 server on any free port in the range given in the
constructor.
|
void |
stop()
Stops the SMTP and POP3 server.
|
javax.mail.internet.MimeMessage |
waitAndGetReceivedMessage()
Does the same as
getReceivedMessage() but waits until a message is received or until a timeout is reached. |
javax.mail.internet.MimeMessage[] |
waitAndGetReceivedMessages(int numMessages)
Does the same as
getReceivedMessages() but waits until a message is received or until a timeout is reached. |
javax.mail.internet.MimeMessage[] |
waitAndGetReceivedMessages(long timeout,
int numMessages)
Does the same as
getReceivedMessages() but waits until a message is received or until specified timeout is reached. |
boolean |
waitForIncomingMessage(int numberOfMessages)
Wait until the specified number of mails is received or until a timeout is reached.
|
boolean |
waitForIncomingMessage(Long timeout,
int numberOfMessages)
Wait until the specified number of mails is received or until specified timeout is reached.
|
public MailServices(int portRangeStart, int portRangeEnd, String hostName)
public void start() throws Exception
BindException
- if there is no free port available in the given rangeException
public void stop()
public boolean isRunning()
public void addUser(String email, String login, String password)
email
- email of the user to be createdlogin
- login of the user to be createdpassword
- password of the user to be createdpublic void addUser(User user)
user
- the user to be created - only the email and password fields are neededpublic void addUser(MailUser user)
public String getHostName()
public int getPop3Port()
public int getSmtpPort()
public int getPort(String protocol)
protocol
- the name of the protocol you want the port number (like "pop3", "pop3s", "smtp", "smtps", "imap", "imaps"...)public void sendTextMessage(String to, String from, String subject, String body)
to
- email address this mail should be sent tofrom
- email address this mail should appear to be sent fromsubject
- subject of the emailbody
- body of the emailpublic void sendMimeMessage(InputStream messageStream)
messageStream
- input stream of the Mime message to sendpublic javax.mail.internet.MimeMessage[] getReceivedMessages()
public javax.mail.internet.MimeMessage getReceivedMessage()
public javax.mail.internet.MimeMessage waitAndGetReceivedMessage()
getReceivedMessage()
but waits until a message is received or until a timeout is reached.InterruptedException
public javax.mail.internet.MimeMessage[] waitAndGetReceivedMessages(int numMessages)
getReceivedMessages()
but waits until a message is received or until a timeout is reached.InterruptedException
public javax.mail.internet.MimeMessage[] waitAndGetReceivedMessages(long timeout, int numMessages)
getReceivedMessages()
but waits until a message is received or until specified timeout is reached.InterruptedException
public void removeAllReceivedMessages() throws com.icegreen.greenmail.store.FolderException
com.icegreen.greenmail.store.FolderException
public boolean waitForIncomingMessage(int numberOfMessages)
public boolean waitForIncomingMessage(Long timeout, int numberOfMessages)
Copyright © 2003–2017 Atlassian. All rights reserved.