如何为playframework 2.5.x安装和配置play-mailer

时间:2018-07-07 09:56:00

标签: scala playframework

我正在尝试在playframework 2.5.x内安装play-mailer插件,但似乎无法安装。我已经阅读了readMe上的文档,但似乎无法理解。

以下是文档中的一些示例代码

要开始使用,请将play-mailer和play-mailer-guice添加为SBT中的依赖项:

libraryDependencies += "com.typesafe.play" %% "play-mailer" % "6.0.1"
libraryDependencies += "com.typesafe.play" %% "play-mailer-guice" % "6.0.1"

play.mailer {
  host = "example.com" // (mandatory)
  port = 25 // (defaults to 25)
  ssl = no // (defaults to no)
  tls = no // (defaults to no)
  tlsRequired = no // (defaults to no)
  user = null // (optional)
  password = null // (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 = no // (defaults to no, will only log all the email properties instead of sending an email)
}

其余文档可在此处找到 https://github.com/playframework/play-mailer

有人可以告诉我如何安装和配置此插件

当我尝试使用sbt命令安装它时,出现以下错误

[info] Set current project to play-mailer-root (in build file:/C:/Users/Alexis/Downloads/myscript/play-mailer-root/)

当我单击“运行”时,我得到的输出是

[warn] Credentials file C:\Users\Alexis\.bintray\.credentials does not exist
[trace] Stack trace suppressed: run last play-mailer-root/compile:backgroundRun for the full output.
[error] (play-mailer-root/compile:backgroundRun) No main class detected.

谢谢

2 个答案:

答案 0 :(得分:0)

将以下内容添加到您的AddButton文件中,然后再次运行sbt

~/.bintray/.credentials

答案 1 :(得分:0)

将此添加到build.sbt中:

"com.typesafe.play" %% "play-mailer" % "6.0.0",
"com.typesafe.play" %% "play-mailer-guice" % "6.0.0",

您可以使用后:

play.mailer {
  host = "smtp.gmail.com" // (mandatory)
  port = 465 // (defaults to 25)
  ssl = yes // (defaults to no)
  tls = no // (defaults to no)
  tlsRequired = no // (defaults to no)
  user = "email@gmail.com"   // (optional)
  password = "password" // (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 = 300 // (defaults to 60s in milliseconds)
  mock = no // (defaults to no, will only log all the email properties instead of sending an email)
}

您可以发送电子邮件:

try {
            Email email = new Email();          
            email.setSubject(subjet);
            email.setFrom("<"+conf.getString("app.mail.from")+">");
            email.addTo("<"+to+">");
            if(fileName != null) {
                email .addAttachment(fileName, file);
            }       
            email.setBodyHtml(htmlBody);    
            mailerClient.send(email);
        }catch(Exception e) {
            Logger.debug("mail() / "+e); 
            throw e;
        }