从 Ktor 应用程序发送电子邮件
Sending Emails From Ktor Application
我目前正在使用 Ktor Netty 引擎创建我的应用程序
我在文档中搜索了在用户向我的服务器发送请求时处理发送电子邮件的任何功能,但一无所获。
post("/api/v1/auth") {
// TODO send email when request is sent!
}
Ktor 中没有用于发送电子邮件的内置功能。
Ktor apache-email-commons 中有一个 java 依赖项可用
implementation("org.apache.commons:commons-email:1.5")
然后使用 SMTP 服务器,例如Gmail:
val email = SimpleEmail()
email.hostName = "smtp.googlemail.com"
email.setSmtpPort(465)
email.setAuthenticator(DefaultAuthenticator("email-account", "account-password"))
email.isSSLOnConnect = true
email.setFrom("sender-email-account")
email.subject = "email-subject"
email.setMsg("message-content")
email.addTo("target-email-address")
email.send()
我目前正在使用 Ktor Netty 引擎创建我的应用程序
我在文档中搜索了在用户向我的服务器发送请求时处理发送电子邮件的任何功能,但一无所获。
post("/api/v1/auth") {
// TODO send email when request is sent!
}
Ktor 中没有用于发送电子邮件的内置功能。
Ktor apache-email-commons 中有一个 java 依赖项可用
implementation("org.apache.commons:commons-email:1.5")
然后使用 SMTP 服务器,例如Gmail:
val email = SimpleEmail()
email.hostName = "smtp.googlemail.com"
email.setSmtpPort(465)
email.setAuthenticator(DefaultAuthenticator("email-account", "account-password"))
email.isSSLOnConnect = true
email.setFrom("sender-email-account")
email.subject = "email-subject"
email.setMsg("message-content")
email.addTo("target-email-address")
email.send()