4

我正在为一个项目使用 play 2.0,并且我正在尝试向用户发送电子邮件。我使用这个插件 [https://github.com/typesafehub/play-plugins/tree/master/mailer]。

在我的 Build.scala 我添加

 "com.typesafe" %% "play-plugins-mailer" % "2.0.4" 

并在 conf/play.plugins

 1500:com.typesafe.plugin.CommonsMailerPlugin

在我的 conf/application.conf 我有设置

 smtp.host=smtp.gmail.com
 smtp.port=25
 smtp.ssl=true
 smtp.tls=false
 smtp.username="test@gmail.com"
 smtp.password="xxxxxxx"

我的控制器动作是

 public static Result sendEmail(String recipt, String title, String sender ){
    MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
      mail.setSubject(SUBJECT);
      mail.addRecipient(recipt);
      mail.addFrom(sender);
      String body = views.html.teams.mailBody.render(recipt, title, sender).body();
      mail.sendHtml(body);
      return ok();
 }

我收到以下错误

[EmailException: Sending the email to the following server failed : smtp.gmail.com:25]

我做错了什么。任何帮助将不胜感激。

谢谢

4

2 回答 2

8

Gmail 的 SMTP 配置不同(在端口 587 上启用了 TLS 进行保护)。

试试这个配置:

smtp.host=smtp.gmail.com
smtp.port=587
smtp.ssl=true
smtp.tls=true
smtp.username="test@gmail.com"
smtp.password="xxxxxxx"
于 2013-01-22T11:09:17.650 回答
4

刚刚浪费了一个小时,这有效:

smtp.user="test@gmail.com"
smtp.password="xxxxxxx"

smtp.user 不是 smtp.username

于 2013-02-05T11:07:00.457 回答