playframework-2.6 - 无法使用 play-mailer 创建应用程序
问题描述
我正在尝试集成play-mailer
到我的应用程序中 - https://github.com/playframework/play-mailer#usage
我正在使用编译时注入。
到目前为止,在我的自定义应用程序加载器中,我具有混合MailerComponents
特征(https://github.com/playframework/play-mailer/blob/master/play-mailer/src/main/scala/play/api/libs/mailer/ MailerComponents.scala)。
里面的配置application.conf
是
play.mailer {
host = localhost // (mandatory)
port = 25 // (defaults to 25)
ssl = no // (defaults to no)
tls = no // (defaults to no)
tlsRequired = no // (defaults to no)
user = Administrator // (optional) //TODOM - am I suppose to enter the password here?
password = codinngjedi // (optional)
debug = no // (defaults to no, to take effect you also need to set the log level to "DEBUG" for the application logger)
timeout = null // (defaults to 60s in milliseconds)
connectiontimeout = null // (defaults to 60s in milliseconds)
mock = true// (defaults to no, will only log all the email properties instead of sending an email)
}
我创建了一个MailerService
如下:
package services
import play.api.libs.mailer._
class MailerService(mailerClient: MailerClient) {
def sendEmail = {
val email = Email("Simple email", "Mister FROM <from@email.com>", Seq("Miss TO <to@email.com>"), bodyText = Some("A text message"))
mailerClient.send(email)
}
}
在我的 customAppLoader
中,我创建了一个MailerService
如下实例:
val mailerService = new MailerService(mailerClient) //mailerClient is defined in MailerComponents of play-mailer library
我的代码没有编译,因为我需要提供config
所需的定义MailerComponents
trait MailerComponents {
def config: Config
lazy val mailerClient: SMTPMailer = new SMTPMailer(new SMTPConfigurationProvider(config).get())
}
但我不知道该怎么做。play-mailer
文档说那我By default the Mailer Plugin will automatically configure the injected instance with the application.conf.
为什么需要提供config
以及如何创建它?
解决方案
我可以定义config
为
import com.typesafe.config.{Config, ConfigFactory}
def config:Config = {
val loadedConfig = ConfigFactory.load() //I suppose play looks for application.conf by default
println("loaded config is "+loadedConfig)
loadedConfig
}
推荐阅读
- apache-kafka-connect - 融合云是否允许自定义连接器部署
- c - FATFS f_write 和 f_close 执行速度不一致
- html - 是否可以使 SVG 中的此图像具有响应性?
- apache-flink - Flink减少没有窗口的键控流
- javascript - 从输入字段中获取多个值并将它们附加到新行中
- debugging - GDB 中断命令不会在命令文件中执行
- php - 如何在 mysql 数据库中的 laravel 中保存多个输入?
- sql-server - 使用来自 OLAP 的 OPENQUERY 转换失败
- python - openpyxl library StopIteration error when opening xlsx file
- machine-learning - 在命名实体识别任务中,条件随机场是双向的吗?