Class SimpleSmtpServer

  • All Implemented Interfaces:
    java.lang.Runnable

    public class SimpleSmtpServer
    extends java.lang.Object
    implements java.lang.Runnable
    Dummy SMTP server for testing purposes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_SMTP_PORT
      Default SMTP port is 25.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleSmtpServer​(int port)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Iterator getReceivedEmail()
      Get email received by this instance since start up.
      int getReceivedEmailSize()
      Get the number of messages received.
      boolean isStopped()
      Check if the server has been placed in a stopped state.
      void run()
      Main loop of the SMTP server.
      static SimpleSmtpServer start()
      Creates an instance of SimpleSmtpServer and starts it.
      static SimpleSmtpServer start​(int port)
      Creates an instance of SimpleSmtpServer and starts it.
      void stop()
      Stops the server.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_SMTP_PORT

        public static final int DEFAULT_SMTP_PORT
        Default SMTP port is 25.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SimpleSmtpServer

        public SimpleSmtpServer​(int port)
        Constructor.
        Parameters:
        port - port number
    • Method Detail

      • run

        public void run()
        Main loop of the SMTP server.
        Specified by:
        run in interface java.lang.Runnable
      • 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
      • stop

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

        public java.util.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
      • 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