com.dumbster.smtp

Class SimpleSmtpServer

public class SimpleSmtpServer extends Object implements Runnable

Dummy SMTP server for testing purposes.

UNKNOWN: constructor allowing user to pass preinitialized ServerSocket

Field Summary
static intDEFAULT_SMTP_PORT
Default SMTP port is 25.
Constructor Summary
SimpleSmtpServer(int port)
Constructor.
Method Summary
IteratorgetReceivedEmail()
Get email received by this instance since start up.
intgetReceivedEmailSize()
Get the number of messages received.
booleanisStopped()
Check if the server has been placed in a stopped state.
voidrun()
Main loop of the SMTP server.
static SimpleSmtpServerstart()
Creates an instance of SimpleSmtpServer and starts it.
static SimpleSmtpServerstart(int port)
Creates an instance of SimpleSmtpServer and starts it.
voidstop()
Stops the server.

Field Detail

DEFAULT_SMTP_PORT

public static final int DEFAULT_SMTP_PORT
Default SMTP port is 25.

Constructor Detail

SimpleSmtpServer

public SimpleSmtpServer(int port)
Constructor.

Parameters: port port number

Method Detail

getReceivedEmail

public Iterator getReceivedEmail()
Get email received by this instance since start up.

Returns: List of String

getReceivedEmailSize

public int getReceivedEmailSize()
Get the number of messages received.

Returns: size of received email list

isStopped

public boolean isStopped()
Check if the server has been placed in a stopped state. Allows another thread to stop the server safely.

Returns: true if the server has been sent a stop signal, false otherwise

run

public void run()
Main loop of the SMTP server.

start

public static SimpleSmtpServer start()
Creates an instance of SimpleSmtpServer and starts it. Will listen on the default port.

Returns: a reference to the SMTP server

start

public static SimpleSmtpServer start(int port)
Creates an instance of SimpleSmtpServer and starts it.

Parameters: port port number the server should listen to

Returns: a reference to the SMTP server

stop

public void stop()
Stops the server. Server is shutdown after processing of the current request is complete.