Package ch.astorm.smtp4j
Class SmtpServerBuilder
java.lang.Object
ch.astorm.smtp4j.SmtpServerBuilder
Helper to build a new
SmtpServer.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theSmtpServer.start()Builds theSmtpServerand starts it.Adds the givenhandlerto authenticate a client.withConnectionListener(ConnectionListener connectionListener) Sets the specifiedconnectionListener.Defines a custom connection string when a new client connects.withDebugStream(PrintStream stream) Defines thePrintStreamto use for debugging.Defines a custom function to generate theSmtpCommand.Type.EHLOresponse.withExecutorService(Supplier<ExecutorService> executorSupplier) Defines theExecutorServicesupplier to use to handle the SMTP messages.withListener(SmtpServerListener listener) Adds the specifiedlisteneronce de server is built.withMaxMessageSize(int limit) Defines the maximum message size (in bytes).withMessageHandler(SmtpMessageHandler messageHandler) Defines theSmtpMessageHandlerto be applied for the received messages.withOptions(SmtpServerOptions options) Defines the SMTP server options..withPort(int port) Defines the port on which theSmtpServerwill listen to.withProtocol(SmtpServerOptions.Protocol protocol) Defines the protocol to used.Defines theSmtpTransactionHandlerFactoryto use to handle SMTP transactions.withSocketTimeout(int timeout) Defines the specifiedtimeout(in milliseconds) for theread()operations on socket input.withSSLContextProvider(SSLContextProvider provider) Defines theSSLContextProviderto use when negotiating SSL.withStartTLSRequired(boolean tlsRequired) Defines if secure transport layer is required (false by default).withStartTLSSupport(boolean startTlsSupport) Defines if theSTARTTLSsupport is enabled (false by default).Adds the givenuserto the repository.
-
Constructor Details
-
SmtpServerBuilder
public SmtpServerBuilder()
-
-
Method Details
-
withPort
Defines the port on which theSmtpServerwill listen to. If the port is less or equal to zero, the server will make a dynamic lookup when it is started. By default, the port is undefined.- Parameters:
port- The port.- Returns:
- This builder.
- See Also:
-
withOptions
Defines the SMTP server options..- Parameters:
options- The options.- Returns:
- This builder.
- See Also:
-
withStartTLSSupport
Defines if theSTARTTLSsupport is enabled (false by default). If true, then aSSL context providermust be set.- Parameters:
startTlsSupport- True if theSTARTTLSsupport must be enabled.- Returns:
- This builder.
- See Also:
-
withStartTLSRequired
Defines if secure transport layer is required (false by default). This value is used only whenTLS supportis enabled.- Parameters:
tlsRequired- True ifSTARTTLSis required once connected.- Returns:
- This builder.
- See Also:
-
withProtocol
Defines the protocol to used. If theSmtpServerOptions.Protocol.SMTPSis used, then aSSL context providermust be set.- Parameters:
protocol- The protocol (by defaultSmtpServerOptions.Protocol.SMTP.)- Returns:
- This builder.
- See Also:
-
withSSLContextProvider
Defines theSSLContextProviderto use when negotiating SSL. By default, the SSL context provider is undefined.- Parameters:
provider- The provider.- Returns:
- This builder.
- See Also:
-
withMaxMessageSize
Defines the maximum message size (in bytes). A value less or equal than zero disables the size limit. By default, there is no message limit.- Parameters:
limit- The size limit in bytes.- Returns:
- This builder.
- See Also:
-
withDebugStream
Defines thePrintStreamto use for debugging. If null, then no debug output will be printed.- Parameters:
stream- The debug stream.- Returns:
- This builder.
- See Also:
-
withConnectionString
Defines a custom connection string when a new client connects.- Parameters:
str- A simple connection answer or null.- Returns:
- This builder.
- See Also:
-
withEHLOResponseFunction
Defines a custom function to generate theSmtpCommand.Type.EHLOresponse. The function input is the parameter sent by the client in the protocol and might be null.- Parameters:
func- The function to apply.- Returns:
- This builder.
- See Also:
-
withAuthenticator
Adds the givenhandlerto authenticate a client. This method can be called multiple times to allow many authentication schemes. Since the authentication will be required, you'll need todeclare some usersotherwise all the connections will be rejected.- Parameters:
handler- The authentication handler.- Returns:
- This builder.
- See Also:
-
withUser
Adds the givenuserto the repository. This method can be called multiple times to add users. Users are not linked to mailboxes. They are only used in the context of the authentication. It is useless to register users if there is noauthentication schemeregistered.- Parameters:
user- The username.password- The associated password.- Returns:
- This builder.
- See Also:
-
withMessageHandler
Defines theSmtpMessageHandlerto be applied for the received messages.- Parameters:
messageHandler- The message handler.- Returns:
- This builder.
- See Also:
-
withExecutorService
Defines theExecutorServicesupplier to use to handle the SMTP messages.- Parameters:
executorSupplier- TheExecutorServiceto use or null (will default toExecutors.newWorkStealingPool()).- Returns:
- This builder.
- See Also:
-
withSmtpTransactionHandlerFactory
Defines theSmtpTransactionHandlerFactoryto use to handle SMTP transactions.- Parameters:
factory- TheSmtpTransactionHandlerFactoryto use or null (will default toDefaultSmtpTransactionHandler).- Returns:
- This builder.
- See Also:
-
withListener
Adds the specifiedlisteneronce de server is built.- Parameters:
listener- The listener to add.- Returns:
- This builder.
- See Also:
-
withSocketTimeout
Defines the specifiedtimeout(in milliseconds) for theread()operations on socket input. By default, this value is set to 10000.- Parameters:
timeout- The socket timeout or zero to disable timeout.- Returns:
- This builder.
- See Also:
-
withConnectionListener
Sets the specifiedconnectionListener.- Parameters:
connectionListener- The connection listener or null.- Returns:
- This builder.
- See Also:
-
build
Builds theSmtpServer.- Returns:
- A new
SmtpServerinstance (not started).
-
start
Builds theSmtpServerand starts it. This is equivalent to callbuild()and thenSmtpServer.start().- Returns:
- A new
SmtpServerinstance (started). - Throws:
IOException
-