如何为playframework 2.5.x安装和配置play-mailer [英] How to install and configure play-mailer, for playframework 2.5.x

查看:65
本文介绍了如何为playframework 2.5.x安装和配置play-mailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to install the play-mailer plugin inside playframework 2.5.x but I cannot seem to install it. I have read the documentation on the readMe, but can't seem to make heads or tails of it.

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

Here are some sample code from the documentation

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

To get started you add play-mailer and play-mailer-guice as a dependency in 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

The rest of the documentation can be found here https://github.com/playframework/play-mailer

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

Can someone show me how to install and configure this plugin

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

When i try to install it using the sbt command I get the following errors

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

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

and when I click run here is the output I get

[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.

谢谢

推荐答案

将此内容添加到build.sbt中:

add this in 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;
        }

这篇关于如何为playframework 2.5.x安装和配置play-mailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆