This repository was archived by the owner on May 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
simplekotlinmail-client/src/jvmMain/kotlin/net/axay/simplekotlinmail/delivery Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -4,20 +4,14 @@ import kotlinx.coroutines.*
44import org.simplejavamail.api.email.Email
55import org.simplejavamail.api.mailer.Mailer
66
7- /* *
8- * The default mailer instance, that is used if
9- * the no other instance is provided.
10- */
11- val DEFAULT_MAILER = mailerBuilder(" localhost" , 25 )
12-
137/* *
148 * Send this email.
159 * @param mailer the mailer which should be used to deliver the message
1610 * @param onException optional callback which should be executed if an error occurs
1711 * @param onSuccess optional callback which should be executed if the message was delivered successfully
1812 */
1913suspend fun Email.send (
20- mailer : Mailer = DEFAULT_MAILER ,
14+ mailer : Mailer = MailerManager .defaultMailer ,
2115 onException : suspend (Exception ) -> Unit = {},
2216 onSuccess : suspend () -> Unit = {}
2317) = withContext(Dispatchers .IO ) {
@@ -33,4 +27,4 @@ suspend fun Email.send(
3327 * Send this email synchronously.
3428 * @param mailer the mailer which should be used to deliver the message
3529 */
36- fun Email.sendSync (mailer : Mailer = DEFAULT_MAILER ) = mailer.sendMail(this )
30+ fun Email.sendSync (mailer : Mailer = MailerManager .defaultMailer ) = mailer.sendMail(this )
Original file line number Diff line number Diff line change 1+ package net.axay.simplekotlinmail.delivery
2+
3+ import org.simplejavamail.api.mailer.Mailer
4+
5+ object MailerManager {
6+
7+ private val LOCAL_MAILER by lazy { mailerBuilder(" localhost" , 25 ) }
8+
9+ private var DEFAULT_MAILER : Mailer ? = null
10+
11+ /* *
12+ * The default mailer instance, that is used if
13+ * the no other instance is provided.
14+ */
15+ var defaultMailer: Mailer
16+ get() = DEFAULT_MAILER ? : LOCAL_MAILER
17+ set(value) {
18+ DEFAULT_MAILER = value
19+ }
20+
21+ }
You can’t perform that action at this time.
0 commit comments