ktor - 从 Ktor 应用程序发送电子邮件
问题描述
我目前正在使用 Ktor Netty Engine 创建我的应用程序
当用户向我的服务器发送请求但一无所获时,我在文档中搜索了任何处理发送电子邮件的功能。
post("/api/v1/auth") {
// TODO send email when request is sent!
}
解决方案
在 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()
推荐阅读
- matlab - 成对相似性和排序样本
- c++ - 从 strcpy_s 获取“L 缓冲区太小 && 0”错误 - 尝试创建重载的 + 运算符
- .net - 在 .NET 中,您可以设置对象的 GC 生成,或者以其他方式指示它即将超出范围吗?
- c# - Razor 页面模型绑定错误上的 SelectList
- python - 我想挑选一列 DataFrame 但结果自动按值排序
- scala - Scala 是否保证存在隐含时的连贯性?
- sql - 如何通过 select 语句中的 id 从另一个表中选择?
- java - SpringBoot oracle.jdbc.OracleDatabaseException:ORA-00932:不一致的数据类型:预期的 DATE 得到了 NUMBER
- python - 如果用户不输入任何内容,则尝试使函数循环并中断
- lua - 卢阿!没想到