TLS¶
TLS (Transport Layer Security) allows you to secure the Simple Mail Transfer Protocol.
You probably want to let your proxy handle TLS, this guide is for TLS in tests.
TLSContext (SSLContext)¶
SimpleKotlinMail provides a utility function allowing you to easily create a new TLSContext (actually an SSLContext).
val tlsContext = TLSContext(
File("path/to/keystore"), keyStorePassphrase = "passphrase",
File("path/to/truststore"), trustStorePassphrase = "passphrase"
)
If you need a keystore and truststore for testing purposes, you can download both from the OpenJDK repository.
Secure the SMTP server¶
Use the setupTLS
function inside an SMTP server builder.
smtpServer {
setupTLS(tlsContext)
}
Currently, TLSv1.3 and TLSv1.2 are enabled by default, but you can change that (example below).
or if you need more options
setupTLS(
tlsContext,
requireTLS = true,
protocolVersions = listOf(TLSVersions.TLS_1_3),
requireClientAuth = true
) {
// configure the SSLSocket to your liking
}
Secure the Mailer¶
Inside a mailer builder, you can set the transport strategy:
mailerBuilder {
// STARTTLS
withTransportStrategy(TransportStrategy.SMTP_TLS)
// or complete TLS encryption
withTransportStrategy(TransportStrategy.SMTPS)
}