Add email configuration for Mailpit and implement email sending logic
This commit is contained in:
1 parent
5b0d79e788
commit
0196fccf60
5 files changed
+46
-3
No files matched your search
@@ -47,10 +47,17 @@ java -jar server/build/libs/server-all.jar
|
||||
|
||||
## Konfiguration
|
||||
|
||||
Die Konfiguration der Anwendung (z.B. Port, Ollama URL) befindet sich in:
|
||||
- `server/src/main/resources/application.yaml`
|
||||
Die Konfiguration der Anwendung (z.B. Port, Ollama URL, E-Mail-Einstellungen) befindet sich in:
|
||||
- `server/src/main/resources/application.yaml` (Server-Port und E-Mail-Konfiguration für Mailpit)
|
||||
- `server/src/main/kotlin/Frameworks.kt` (Ollama Base URL)
|
||||
|
||||
### E-Mail-Konfiguration (Testen mit Mailpit)
|
||||
Für Testzwecke ist die App auf Mailpit konfiguriert:
|
||||
- **Host**: `mailpit.rwcloud.ch`
|
||||
- **Port**: `1025`
|
||||
- **Sender**: `info@rwcloud.ch`
|
||||
- **Empfänger**: `transport@rwcloud.ch`
|
||||
|
||||
## Verwendete Technologien
|
||||
|
||||
- [Ktor](https://ktor.io/) - Web Framework
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
htmx.org@2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/htmx.org/-/htmx.org-2.0.3.tgz#83f76a53d3fc562fe839f0f57ee7cd5f75fe7b59"
|
||||
integrity sha512-AeoJUAjkCVVajbfKX+3sVQBTCt8Ct4lif1T+z/tptTXo8+8yyq3QIMQQe/IT+R8ssfrO1I0DeX4CAronzCL6oA==
|
||||
@@ -42,6 +42,7 @@ dependencies {
|
||||
implementation("io.ktor:ktor-server-netty")
|
||||
implementation("ch.qos.logback:logback-classic:$logback_version")
|
||||
implementation("io.ktor:ktor-server-config-yaml")
|
||||
implementation("org.apache.commons:commons-email:1.6.0")
|
||||
testImplementation("io.ktor:ktor-server-test-host")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
||||
}
|
||||
@@ -22,8 +22,14 @@ import kotlinx.serialization.Serializable
|
||||
import io.ktor.server.request.*
|
||||
import java.time.LocalTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import org.apache.commons.mail.SimpleEmail
|
||||
|
||||
fun Application.configureRouting() {
|
||||
val mailHost = environment.config.propertyOrNull("mail.host")?.getString() ?: "localhost"
|
||||
val mailPort = environment.config.propertyOrNull("mail.port")?.getString()?.toInt() ?: 1025
|
||||
val mailSender = environment.config.propertyOrNull("mail.sender")?.getString() ?: "info@example.com"
|
||||
val mailRecipient = environment.config.propertyOrNull("mail.recipient")?.getString() ?: "transport@example.com"
|
||||
|
||||
routing {
|
||||
staticResources("/", "/web")
|
||||
|
||||
@@ -65,7 +71,22 @@ fun Application.configureRouting() {
|
||||
prompt
|
||||
}
|
||||
|
||||
call.respondText(generatedEmail)
|
||||
// E-Mail versenden
|
||||
val emailStatus = try {
|
||||
val email = SimpleEmail()
|
||||
email.hostName = mailHost
|
||||
email.setSmtpPort(mailPort)
|
||||
email.setFrom(mailSender)
|
||||
email.subject = "Transportbestellung: $name"
|
||||
email.setMsg(generatedEmail)
|
||||
email.addTo(mailRecipient)
|
||||
email.send()
|
||||
"E-Mail erfolgreich versendet an $mailRecipient"
|
||||
} catch (e: Exception) {
|
||||
"Fehler beim E-Mail-Versand: ${e.message}"
|
||||
}
|
||||
|
||||
call.respondText("$generatedEmail\n\n--- Status ---\n$emailStatus")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,9 @@ ktor:
|
||||
- ch.rwcloud.ApplicationKt.module
|
||||
deployment:
|
||||
port: 8080
|
||||
|
||||
mail:
|
||||
host: "mailpit.rwcloud.ch"
|
||||
port: 1025
|
||||
sender: "info@rwcloud.ch"
|
||||
recipient: "transport@rwcloud.ch"
|
||||
Reference in new issue
Block a user