Class SMTPServer

java.lang.Object
org.subethamail.smtp.server.SMTPServer

public class SMTPServer extends Object
Main SMTPServer class. Construct this object, set the hostName, port, and bind address if you wish to override the defaults, and call start(). This class starts opens a ServerSocket and creates a new instance of the ConnectionHandler class when a new connection comes in. The ConnectionHandler then parses the incoming SMTP stream and hands off the processing to the CommandHandler which will execute the appropriate SMTP command class. To use this class, construct a server with your implementation of the MessageHandlerFactory. This provides low-level callbacks at various phases of the SMTP exchange. For a higher-level but more limited interface, you can pass in a org.subethamail.smtp.helper.SimpleMessageListenerAdapter. By default, no authentication methods are offered. To use authentication, set an AuthenticationHandlerFactory.
Author:
Jon Stevens, Ian McFarland <ian@neo.com>, Jeff Schnitzer
  • Constructor Details

  • Method Details

    • getHostName

      public String getHostName()
      Returns:
      the host name that will be reported to SMTP clients
    • setHostName

      public void setHostName(String hostName)
      The host name that will be reported to SMTP clients
    • getBindAddress

      public InetAddress getBindAddress()
      null means all interfaces
    • setBindAddress

      public void setBindAddress(InetAddress bindAddress)
      null means all interfaces
    • getPort

      public int getPort()
    • setPort

      public void setPort(int port)
    • getSoftwareName

      public String getSoftwareName()
      The string reported to the public as the software running here. Defaults to SubEthaSTP and the version number.
    • setSoftwareName

      public void setSoftwareName(String value)
      Changes the publicly reported software information.
    • getExecutorService

      public ExecutorService getExecutorService()
      Returns:
      the ExecutorService handling client connections
    • isRunning

      public boolean isRunning()
      Is the server running after start() has been called?
    • getBacklog

      public int getBacklog()
      The backlog is the Socket backlog. The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.
      Returns:
      the backlog
    • setBacklog

      public void setBacklog(int backlog)
      The backlog is the Socket backlog. The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.
    • start

      public void start()
      Call this method to get things rolling after instantiating the SMTPServer.

      An SMTPServer which has been shut down, must not be reused.

    • stop

      public void stop()
      Shut things down gracefully.
    • createServerSocket

      protected ServerSocket createServerSocket() throws IOException
      Override this method if you want to create your own server sockets. You must return a bound ServerSocket instance
      Throws:
      IOException
    • createSSLSocket

      public SSLSocket createSSLSocket(Socket socket) throws IOException
      Create a SSL socket that wraps the existing socket. This method is called after the client issued the STARTTLS command.

      Subclasses may override this method to configure the key stores, enabled protocols/ cipher suites, enforce client authentication, etc.

      Parameters:
      socket - the existing socket as created by createServerSocket() (not null)
      Returns:
      a SSLSocket
      Throws:
      IOException - when creating the socket failed
    • getDisplayableLocalSocketAddress

      public String getDisplayableLocalSocketAddress()
    • getMessageHandlerFactory

      public MessageHandlerFactory getMessageHandlerFactory()
      Returns:
      the factory for message handlers, cannot be null
    • setMessageHandlerFactory

      public void setMessageHandlerFactory(MessageHandlerFactory fact)
    • getAuthenticationHandlerFactory

      public AuthenticationHandlerFactory getAuthenticationHandlerFactory()
      Returns:
      the factory for auth handlers, or null if no such factory has been set.
    • setAuthenticationHandlerFactory

      public void setAuthenticationHandlerFactory(AuthenticationHandlerFactory fact)
    • getCommandHandler

      public CommandHandler getCommandHandler()
      The CommandHandler manages handling the SMTP commands such as QUIT, MAIL, RCPT, DATA, etc.
      Returns:
      An instance of CommandHandler
    • getMaxConnections

      public int getMaxConnections()
    • setMaxConnections

      public void setMaxConnections(int maxConnections)
      Set's the maximum number of connections this server instance will accept.
      Parameters:
      maxConnections -
    • getConnectionTimeout

      public int getConnectionTimeout()
    • setConnectionTimeout

      public void setConnectionTimeout(int connectionTimeout)
      Set the number of milliseconds that the server will wait for client input. Sometime after this period expires, an client will be rejected and the connection closed.
    • getMaxRecipients

      public int getMaxRecipients()
    • setMaxRecipients

      public void setMaxRecipients(int maxRecipients)
      Set the maximum number of recipients allowed for each message. A value of -1 means "unlimited".
    • setEnableTLS

      public void setEnableTLS(boolean enableTLS)
      If set to true, TLS will be supported.

      The minimal JSSE configuration necessary for a working TLS support on Oracle JRE 6:

      • javax.net.ssl.keyStore system property must refer to a file containing a JKS keystore with the private key.
      • javax.net.ssl.keyStorePassword system property must specify the keystore password.

      Up to SubEthaSMTP 3.1.5 the default was true, i.e. TLS was enabled.

      See Also:
    • getEnableTLS

      public boolean getEnableTLS()
    • getDisableTLS

      @Deprecated public boolean getDisableTLS()
      Deprecated.
      use enableTLS
    • setDisableTLS

      @Deprecated public void setDisableTLS(boolean value)
      Deprecated.
    • getHideTLS

      public boolean getHideTLS()
    • setHideTLS

      public void setHideTLS(boolean value)
      If set to true, TLS will not be advertised in the EHLO string. Default is false; true implied when disableTLS=true.
    • getRequireTLS

      public boolean getRequireTLS()
    • setRequireTLS

      public void setRequireTLS(boolean requireTLS)
      Parameters:
      requireTLS - true to require a TLS handshake, false to allow operation with or without TLS. Default is false; ignored when disableTLS=true.
    • getRequireAuth

      public boolean getRequireAuth()
    • setRequireAuth

      public void setRequireAuth(boolean requireAuth)
      Parameters:
      requireAuth - true for mandatory smtp authentication, i.e. no mail mail be accepted until authentication succeeds. Don't forget to set AuthenticationHandlerFactory to allow client authentication. Defaults to false.
    • getMaxMessageSize

      public int getMaxMessageSize()
      Returns:
      the maxMessageSize
    • setMaxMessageSize

      public void setMaxMessageSize(int maxMessageSize)
      Parameters:
      maxMessageSize - the maxMessageSize to set
    • getDisableReceivedHeaders

      public boolean getDisableReceivedHeaders()
    • setDisableReceivedHeaders

      public void setDisableReceivedHeaders(boolean disableReceivedHeaders)
      Parameters:
      disableReceivedHeaders - false to include Received headers. Default is false.
    • getSessionIdFactory

      public SessionIdFactory getSessionIdFactory()
    • setSessionIdFactory

      public void setSessionIdFactory(SessionIdFactory sessionIdFactory)
      Sets the SessionIdFactory which will allocate a unique identifier for each mail sessions. If not set, a reasonable default will be used.