@@ -2,18 +2,21 @@ package net.axay.simplekotlinmail.test
22
33import kotlinx.coroutines.runBlocking
44import net.axay.simplekotlinmail.delivery.MailerManager
5- import net.axay.simplekotlinmail.delivery.send
5+ import net.axay.simplekotlinmail.delivery.mailerBuilder
6+ import net.axay.simplekotlinmail.delivery.sendSync
67import net.axay.simplekotlinmail.email.emailBuilder
78import net.axay.simplekotlinmail.server.smtpServer
89import net.axay.simplekotlinmail.server.start
910import net.axay.simplekotlinmail.server.tls.TLSContext
1011import net.axay.simplekotlinmail.server.tls.setupTLS
12+ import net.axay.simplekotlinmail.server.utils.session
13+ import net.axay.simplekotlinmail.server.utils.sslSocket
1114import org.junit.jupiter.api.Assertions.assertEquals
1215import org.junit.jupiter.api.Test
16+ import org.simplejavamail.api.mailer.config.TransportStrategy
1317import java.io.File
1418
1519class ServerClientTest {
16-
1720 private val plainText = " Hey, how are you?"
1821
1922 private val email = emailBuilder {
@@ -26,8 +29,7 @@ class ServerClientTest {
2629
2730 @Test
2831 fun testServer () = runBlocking {
29-
30- val smtpServer = smtpServer {
32+ val smtpServer = smtpServer(2500 ) {
3133 mailListener {
3234 println (" received email: ${it.email.plainText} " )
3335 assertEquals(it.email.plainText?.trim(), plainText)
@@ -36,43 +38,43 @@ class ServerClientTest {
3638
3739 smtpServer.start(keepAlive = true )
3840
39- email.send(awaitCompletion = true )
41+ email.sendSync(mailerBuilder(port = 2500 ) )
4042
4143 MailerManager .shutdownMailers()
4244
4345 smtpServer.stop()
44-
4546 }
4647
4748 @Test
4849 fun testServerTLS () = runBlocking {
49-
50- val plainText = " Hey, how are you?"
51-
52- val smtpServer = smtpServer {
50+ val smtpServer = smtpServer(2500 ) {
5351 setupTLS(
5452 TLSContext (
5553 File (" ./src/test/resources/keystore" ), " passphrase" ,
5654 File (" ./src/test/resources/truststore" ), " passphrase"
5755 ),
5856 true ,
57+ starttlsOnly = false ,
5958 requireClientAuth = false
6059 )
6160
6261 mailListener {
6362 println (" received email: ${it.email.plainText} " )
6463 assertEquals(it.email.plainText?.trim(), plainText)
64+ assert (it.context.session?.sslSocket != null )
6565 }
6666 }
6767
6868 smtpServer.start(keepAlive = true )
6969
70- email.send(awaitCompletion = true )
70+ email.sendSync(mailerBuilder(port = 2500 ) {
71+ verifyingServerIdentity(false )
72+ trustingAllHosts(true )
73+ withTransportStrategy(TransportStrategy .SMTPS )
74+ })
7175
7276 MailerManager .shutdownMailers()
7377
7478 smtpServer.stop()
75-
7679 }
77-
7880}
0 commit comments