本文介绍了无法从Play Mailer插件发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的游戏应用程序发送电子邮件.目前,我正在本地主机上运行应用程序.对于电子邮件部分,我正在关注 https://github.com/playframework/play-mailer ,到目前为止已实现: 我将其添加到build.sbt依赖项中:

I'm trying to send emails from my play application. currently I am running application on localhost. for email part I was following this https://github.com/playframework/play-mailer and so far implemented this: I ahve added this to build.sbt dependencies:

 "com.typesafe.play" %% "play-mailer" % "5.0.0-M1"

这是HomeController.Java:

This is HomeController.Java:

 //MAiler Inject
private final MailerClient mailer;
@Inject
public HomeController(MailerClient mailer)
{
    this.mailer = mailer;
}
public void sendEmail() {
    String cid = "1234";
    Email email = new Email();
    email.setSubject("Simple email");
    email.setFrom("[email protected]");
    email.addTo("[email protected]");
    // adds attachment
    // .addAttachment("attachment.pdf", new File("/some/path/attachment.pdf"))
    // adds inline attachment from byte array
    //   .addAttachment("data.txt", "data".getBytes(), "text/plain", "Simple data", EmailAttachment.INLINE)
    // adds cid attachment
    // .addAttachment("image.jpg", new File("/some/path/image.jpg"), cid)
    // sends text, HTML or both...
    email .setBodyText("A text message");
    //    .setBodyHtml("<html><body><p>An <b>html</b> message with cid <img src=\"cid:" + cid + "\"></p></body></html>");
    mailer.send(email);
}

这是application.config

This is application.config

play.mailer {
host="smtp.gmail.com"
port=465
ssl=yes
tls=no
user="[email protected]"
password="mypass"
debug=no
timeout=60
connectiontimeout=60
mock=no
}

例外:

[debug] application - DEBUG: getProvider() returning    javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
[debug] application -

[debug] application - DEBUG SMTP: need username and password for authentication
[debug] application -

[debug] application - DEBUG SMTP: useEhlo true, useAuth true
[debug] application -

[debug] application - DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
[debug] application -

[error] application -

! @6pgje8o34 - Internal server error, for (POST) [/addUser] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:269)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:195)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:98)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)

但是,我没有收到电子邮件.

But, I'm not getting emails.

我正在使用播放2.5.

I'm using play 2.5.

推荐答案

解决了问题.配置和代码都可以. Gmail的安全设置阻止了邮件,您可以从此处打开不太安全的设置(但要谨慎)... https://www.google.com/settings/security/lesssecureapps .一切都会像魅力一样发挥作用. :)

Solved the Problem.. Configuration and codes were all right. Gmail's security settings were blocking the mail, you can turn on less secure settings (but with caution) from here... https://www.google.com/settings/security/lesssecureapps. and it all will work like a charm. :)

这篇关于无法从Play Mailer插件发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:27