小编Uma*_*air的帖子

在play 2.0中发送电子邮件异常

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

在我的Build.scala中,我添加了

 "com.typesafe" %% "play-plugins-mailer" % "2.0.4" 
Run Code Online (Sandbox Code Playgroud)

并在conf/play.plugins中

 1500:com.typesafe.plugin.CommonsMailerPlugin
Run Code Online (Sandbox Code Playgroud)

在我的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"
Run Code Online (Sandbox Code Playgroud)

我的控制器动作是

 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();
 }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

[EmailException: Sending the email to the following server failed : smtp.gmail.com:25]
Run Code Online (Sandbox Code Playgroud)

我做错了什么.任何帮助将受到高度赞赏.

谢谢

java playframework playframework-2.0

4
推荐指数
1
解决办法
1746
查看次数

将Dynamic ArrayList转换为Json

我想将数组列表转换为特定格式的json字符串.我将所有用户的电子邮件都放在数组列表中,并希望将其转换为以下格式的JSON.

 [
  {"email":"abc@gmail.com"},
  {"email":"xyz@gmail.com"}
 ]
Run Code Online (Sandbox Code Playgroud)

我的控制器动作是

 public static Result apiCustomers(){
    List<Customer> customerList = Model.coll(Customer.class).find().toArray();
    List<String> emails = new ArrayList<String>();

    for(Customer c : customerList){
        emails.add(c.email);
    }

    //ObjectNode result = Json.newObject();
    //result.put("emails", Json.toJson(emails));        
    return ok();
}
Run Code Online (Sandbox Code Playgroud)

如何将电子邮件列表转换为上述json格式?

提前致谢

java json playframework-2.0

2
推荐指数
1
解决办法
7384
查看次数

标签 统计

java ×2

playframework-2.0 ×2

json ×1

playframework ×1