Package org.subethamail.wiser
Class Wiser
java.lang.Object
org.subethamail.wiser.Wiser
- All Implemented Interfaces:
SimpleMessageListener
Wiser is a tool for unit testing applications that send mail. Your unit
tests can start Wiser, run tests which generate emails, then examine the
emails that Wiser received and verify their integrity.
Wiser is not intended to be a "real" mail server and is not adequate
for that purpose; it simply stores all mail in memory. Use the
MessageHandlerFactory interface (optionally with the SimpleMessageListenerAdapter)
of SubEthaSMTP instead.
- Author:
- Jon Stevens, Jeff Schnitzer
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAlways accept everythingvoiddeliver(String from, String recipient, InputStream data) Cache the messages in memoryvoiddumpMessages(PrintStream out) For debugging purposes, dumps a rough outline of the messages to the output stream.Returns the list of WiserMessages.protected jakarta.mail.SessionCreates the JavaMail Session object for use in WiserMessagestatic voidA main() for this class.voidsetHostname(String hostname) The hostname that the server should listen on.voidsetPort(int port) The port that the server should listen on.voidstart()Starts the SMTP Servervoidstop()Stops the SMTP Server
-
Field Details
-
messages
-
-
Constructor Details
-
Wiser
public Wiser()Create a new SMTP server with this class as the listener. The default port is 25. Call setPort()/setHostname() before calling start(). -
Wiser
public Wiser(int port) Convenience constructor
-
-
Method Details
-
setPort
public void setPort(int port) The port that the server should listen on.- Parameters:
port-
-
setHostname
The hostname that the server should listen on.- Parameters:
hostname-
-
start
public void start()Starts the SMTP Server -
stop
public void stop()Stops the SMTP Server -
main
A main() for this class. Starts up the server.- Throws:
Exception
-
accept
Always accept everything- Specified by:
acceptin interfaceSimpleMessageListener- Parameters:
from- is a rfc822-compliant email address.recipient- is a rfc822-compliant email address.- Returns:
- true if the listener wants delivery of the message, false if the message is not for this listener.
-
deliver
public void deliver(String from, String recipient, InputStream data) throws TooMuchDataException, IOException Cache the messages in memory- Specified by:
deliverin interfaceSimpleMessageListener- Parameters:
from- is the envelope sender in rfc822 formrecipient- will be an accepted recipient in rfc822 formdata- will be the smtp data stream, stripped of any extra '.' chars. The data stream is only valid for the duration of this call.- Throws:
TooMuchDataException- if the listener can't handle that much data. An error will be reported to the client.IOException- if there is an IO error reading the input data.
-
getSession
protected jakarta.mail.Session getSession()Creates the JavaMail Session object for use in WiserMessage -
getMessages
Returns the list of WiserMessages.The number of mail transactions and the number of mails may be different. If a message is received with multiple recipients in a single mail transaction, then the list will contain more WiserMessage instances, one for each recipient.
-
getServer
- Returns:
- the server implementation
-
dumpMessages
For debugging purposes, dumps a rough outline of the messages to the output stream.- Throws:
jakarta.mail.MessagingException
-