невозможно создать приложение с помощью play-mailer - PullRequest
0 голосов
/ 30 августа 2018

Я пытаюсь интегрировать 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 и как его создать?

1 Ответ

0 голосов
/ 31 августа 2018

Я мог бы определить 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
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...