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.Defines a custom connection string when a new client connects.withDebugStream(PrintStream stream) Defines thePrintStreamto use for debugging.If null, then no debug output will be printed.Defines a custom function to generate theSmtpCommand.Type.EHLOresponse.withExecutorService(ExecutorService executor) Defines theExecutorServiceto use to handle the SMTP messages.withListener(SmtpServerListener listener) Adds the specifiedlisteneronce de server is build.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.withSSLContextProvider(SSLContextProvider provider) Defines theSSLContextProviderto use when negotiating SSL.withStartTLSRequired(boolean tlsRequired) Defines if secure transport layer is required.withStartTLSSupport(boolean startTlsSupport) Defines if theSTARTTLSsupport is enabled (false by default).If true, then aSSL context providermust be set.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 undefined, the server will make a dynamic lookup when it is started.- 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. 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.- 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.- 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 users.- 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.- 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 theExecutorServiceto use to handle the SMTP messages.- Parameters:
executor- TheExecutorServiceto use or null.- Returns:
- This builder.
-
withListener
Adds the specifiedlisteneronce de server is build.- Parameters:
listener- The listener to add.- Returns:
- This builder.
- See Also:
-
build
Builds theSmtpServer.- Returns:
- A new
SmtpServerinstance.
-
start
Builds theSmtpServerand starts it.- Returns:
- A new
SmtpServerinstance. - Throws:
IOException
-