### Setup TLS on SMTP Server Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/tls.md Integrate TLS security into an SMTP server builder using a pre-configured TLSContext. This ensures that all communication with the server is encrypted. ```kotlin smtpServer { setupTLS(tlsContext) } ``` -------------------------------- ### Advanced TLS Setup on SMTP Server Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/tls.md Configure advanced TLS options for an SMTP server, including requiring TLS, specifying protocol versions, and enforcing client authentication. A lambda can be used to further customize the SSLSocket. ```kotlin setupTLS( tlsContext, requireTLS = true, protocolVersions = listOf(TLSVersions.TLS_1_3), requireClientAuth = true ) { // configure the SSLSocket to your liking } ``` -------------------------------- ### Convert Email Object to MimeMessage Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/convert.md Use the `mimeMessage` property of an Email object to get its MimeMessage representation. ```kotlin email.mimeMessage ``` -------------------------------- ### Create a Mailer Instance Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/mailer.md Instantiates a new mailer connected to a specified SMTP server. Requires hostname and port. ```kotlin val mailer = mailerBuilder(host = "your_hostname", port = 25) ``` -------------------------------- ### Create TLSContext for Kotlinmailer Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/tls.md Instantiate a TLSContext using keystore and truststore files with their respective passphrases. This is essential for setting up secure SMTP connections. ```kotlin val tlsContext = TLSContext( File("path/to/keystore"), keyStorePassphrase = "passphrase", File("path/to/truststore"), truststorePassphrase = "passphrase" ) ``` -------------------------------- ### Set Basic HTML Content Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/html.md Use the `withHTML` function within the email builder to define the basic HTML structure of your email. ```kotlin emailBuilder { withHTML { body { h1 { +"Really important question:" } p { +"Hey, how are you today?" } } } } ``` -------------------------------- ### Set Dynamic HTML Content with User Data Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/html.md Utilize kotlinx.html DSL to dynamically generate HTML content, such as personalized greetings and item lists, using existing data variables. ```kotlin val username = "foo" val itemsBought = listOf("banana", "apple") emailBuilder { withHTML { body { h1 { +"We have received your order." } p { +"Thanks for shopping with us $username!" } p { +"You have bought the following items:" } ul { for (item in itemsBought) li { +item } } } } } ``` -------------------------------- ### Copy an Email Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/email.md Create a copy of an existing email to modify its content. This is useful for reusing email structures. ```kotlin val copiedEmail = email.copy { // modify the email } ``` -------------------------------- ### Reply to an Email Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/email.md Reply to an existing email. You can specify the sender, whether to reply to all recipients, and prepend text to the reply. ```kotlin val replyEmail = email.reply(from = "replyaddress@example.org", toAll = false) { prependText("This is a reply message.") } ``` -------------------------------- ### Configure Mailer Transport Strategy for TLS Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/tls.md Set the transport strategy for a mailer to use either STARTTLS (SMTP_TLS) or complete TLS encryption (SMTPS) for secure email transmission. ```kotlin mailerBuilder { // STARTTLS withTransportStrategy(TransportStrategy.SMTP_TLS) // or complete TLS encryption withTransportStrategy(TransportStrategy.SMTPS) } ``` -------------------------------- ### Set Global Default Mailer Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/mailer.md Assigns a created mailer instance as the global default. This mailer will be used if no specific mailer is provided during email sending. ```kotlin MailerManager.defaultMailer = mailer ``` -------------------------------- ### Forward an Email Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/email.md Forward an existing email to a new recipient. You can specify the sender and prepend text to the forwarded message. ```kotlin val forwardEmail = email.forward(from = "forwardaddress@example.org") { prependText("This is a forwarded message.") } ``` -------------------------------- ### Suspend Until Email Completion Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/mailer.md Waits for an asynchronously sent email to complete. The `send()` function returns a Job that can be joined. Exceptions during delivery can be caught. ```kotlin email.send().join() ``` ```kotlin kotlin.runCatching { email.send().join() } .onFailure { it.printStackTrace() } .onSuccess { println("I just sent an email!") } ``` -------------------------------- ### Send Email Synchronously Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/mailer.md Sends an email synchronously, blocking the current thread until completion. This method will throw an exception if the email delivery fails. ```kotlin email.sendSync() // using the default Mailer instance ``` ```kotlin // or email.sendSync(mailer) ``` -------------------------------- ### Convert EML String to Email Object Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/convert.md Use the `toEmail()` extension function to convert an EML formatted string into an Email object. ```kotlin string.toEmail() ``` -------------------------------- ### Send Email Asynchronously (Coroutines) Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/mailer.md Sends an email without blocking the current thread using coroutines. This method requires a CoroutineScope and can use the default mailer or a specific one. ```kotlin email.send() // using the defult Mailer instance ``` ```kotlin // or email.send(mailer) ``` -------------------------------- ### Convert Email Object to EML String Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/convert.md Retrieve the EML formatted string representation of an Email object using the `eml` property. ```kotlin email.eml ``` -------------------------------- ### Convert MimeMessage to Email Object Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/convert.md Access the `email` property on a MimeMessage object to obtain an Email object. ```kotlin mimeMessage.email ``` -------------------------------- ### Shutdown All Mailers Source: https://github.com/bierdav/kotlinmailer/blob/main/docs/Writerside/topics/mailer.md Safely shuts down all active mailer instances. This is necessary to allow the program to exit cleanly as mailers keep the program alive. ```kotlin MailerManager.shutdownMailers() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.