Class ServerSetup

java.lang.Object
com.icegreen.greenmail.util.ServerSetup

public class ServerSetup extends Object
Defines the default ports
smtp25
smtps465
pop3110
pop3s995
imap143
imaps993
Use ServerSetupTest for non-default ports

Since:
Jan 28, 2006 Use ServerSetupTest for non-default ports
Author:
Wael Chatila
  • Field Details

  • Constructor Details

    • ServerSetup

      public ServerSetup(int port, String bindAddress, String protocol)
      Creates a configuration.
      Parameters:
      port - the port for this service. Set to 0 if an available port should be autodetected.
      bindAddress - the bind address, e.g. 'localhost'
      protocol - the protocol, see PROTOCOLS
  • Method Details

    • getLocalHostAddress

      public static String getLocalHostAddress()
    • getDefaultBindAddress

      public String getDefaultBindAddress()
      Gets the public default host address "0.0.0.0".
      Returns:
      the public IP host address.
    • isSecure

      public boolean isSecure()
    • getProtocol

      public String getProtocol()
    • getBindAddress

      public String getBindAddress()
    • getPort

      public int getPort()
    • getConnectionTimeout

      public long getConnectionTimeout()
    • setConnectionTimeout

      public void setConnectionTimeout(long connectionTimeout)
    • getReadTimeout

      public long getReadTimeout()
    • setReadTimeout

      public void setReadTimeout(long readTimeout)
    • getWriteTimeout

      public long getWriteTimeout()
    • setWriteTimeout

      public void setWriteTimeout(long writeTimeout)
    • getServerStartupTimeout

      public long getServerStartupTimeout()
    • withPort

      @Deprecated public ServerSetup withPort(int port)
      Deprecated.
      use port(int) - will be deprecated in 2.1
      Creates a deep copy and updates port.
      Parameters:
      port - the port (0 for dynamic port allocation).
      Returns:
      a modified copy.
    • port

      public ServerSetup port(int port)
      Creates a deep copy and updates port.
      Parameters:
      port - the port (0 for dynamic port allocation).
      Returns:
      a modified copy.
    • isDynamicPort

      public boolean isDynamicPort()
      True if available port gets dynamically allocated.
      Returns:
      true if enabled.
    • dynamicPort

      public ServerSetup dynamicPort()
      Enable dynamic port allocation.
      Returns:
      a modified copy with dynamic port allocation enabled.
    • isVerbose

      public boolean isVerbose()
    • setVerbose

      public ServerSetup setVerbose(boolean verbose)
      Parameters:
      verbose - if true enables JavaMail debug output by setting JavaMail property 'mail.debug'
    • verbose

      public ServerSetup verbose(boolean verbose)
      Creates a deep copy with verbose configured.
      Parameters:
      verbose - if true enables JavaMail debug output by setting JavaMail property 'mail.debug'
      Returns:
      a deep copy with verbose configured
    • setServerStartupTimeout

      public void setServerStartupTimeout(long timeoutInMs)
      Sets the server startup timeout in milliseconds.
      Parameters:
      timeoutInMs - timeout in milliseconds.
    • configureJavaMailSessionProperties

      public Properties configureJavaMailSessionProperties(Properties properties, boolean debug)
      Creates default properties for a JavaMail session.

      Concrete server implementations can add protocol-specific settings.

      Order of application:

      1. Default GreenMail properties - e.g. common properties such as mail.debug when log level is debug or protocol specific settings such as mail.smtp.port
      2. ServerSetup configured mail session properties
      3. Parameter provided properties
      Note: Be careful to not override essential GreenMail provided properties, e.g. mail.PROTOCOL.port

      For details see

      • https://jakarta.ee/specifications/mail/2.0/apidocs/jakarta.mail/module-summary.html for some general settings
      • https://jakarta.ee/specifications/mail/1.6/apidocs/index.html?com/sun/mail/smtp/package-summary.html for valid SMTP properties.
      • https://jakarta.ee/specifications/mail/1.6/apidocs/index.html?com/sun/mail/imap/package-summary.html for valid IMAP properties
      • https://jakarta.ee/specifications/mail/1.6/apidocs/index.html?com/sun/mail/pop3/package-summary.html for valid POP3 properties.
      Parameters:
      properties - additional and optional properties which overwrite automatically added properties. Can be null.
      debug - sets JavaMail debug properties
      Returns:
      default properties.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createCopy

      public ServerSetup createCopy()
      Create a deep copy.
      Returns:
      a copy of the server setup configuration.
    • createCopy

      public ServerSetup createCopy(String bindAddress)
      Create a deep copy.
      Parameters:
      bindAddress - overwrites bind address when creating deep copy.
      Returns:
      a copy of the server setup configuration.
    • createCopy

      public ServerSetup createCopy(int port, String bindAddress, String protocol)
      Create a deep copy.
      Parameters:
      port - overwrites the port.
      bindAddress - overwrites bind address.
      protocol - overwrites the protocol.
      Returns:
      a copy of the server setup configuration.
    • mailSessionProperty

      public ServerSetup mailSessionProperty(String key, String value)
      Create a new server setup copy, configured with given JavaMail session property.

      For protocol-specific properties see

      • https://jakarta.ee/specifications/mail/2.0/apidocs/jakarta.mail/jakarta/mail/package-summary.html for general settings
      • https://jakarta.ee/specifications/mail/1.6/apidocs/index.html?com/sun/mail/smtp/package-summary.html for SMTP properties.
      • https://jakarta.ee/specifications/mail/1.6/apidocs/index.html?com/sun/mail/imap/package-summary.html for IMAP properties
      • https://jakarta.ee/specifications/mail/1.6/apidocs/index.html?com/sun/mail/pop3/package-summary.html for POP3 properties.
      Parameters:
      key - the key
      value - the value
      Returns:
      a deep copy with configured session property
    • createCopy

      public static ServerSetup[] createCopy(ServerSetup[] serverSetups, UnaryOperator<ServerSetup> copyMutator)
      Creates a copy applying given mutator on each copy.
      Parameters:
      serverSetups - the server setups
      copyMutator - the mutator receiving the original server setup and returning a modified copy
      Returns:
      mutated copies
    • verbose

      public static ServerSetup[] verbose(ServerSetup[] serverSetups)
      Creates a copy with verbose mode enabled.
      Parameters:
      serverSetups - the server setups.
      Returns:
      copies of server setups with verbose mode enabled.
    • dynamicPort

      public static ServerSetup[] dynamicPort(ServerSetup[] serverSetups)
      Creates a copy with dynamic ports (auto-detecting available ports) enabled.
      Parameters:
      serverSetups - the server setups.
      Returns:
      copies of server setups with verbose mode enabled.
    • mailSessionProperty

      public static ServerSetup[] mailSessionProperty(ServerSetup[] serverSetups, String key, String value)
      Creates a copy with configured default mail session property.
      Parameters:
      serverSetups - the server setups.
      key - the key
      value - the value
      Returns:
      copies of server setups with verbose mode enabled.
      See Also: