Я пытаюсь интегрировать 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)
}
}
В моем пользовательском AppLoader
я создал экземпляр 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
и как его создать?