我正在尝试从我的Play应用程序发送电子邮件。 电子邮件对象由另一个类准备并传递给将发送电子邮件的控制器。尝试发送电子邮件时,会抛出致命的异常。 我的控制器设置如下:
public class UserController extends BaseController<User> {
@Inject
MailerClient mailerClient;
@Inject
public UserController(MailerClient client) {
super(new UserService());
mailerClient = client;
}
public Result create(){
resourceForm = formFactory.form(User.class);
Form<User> filledForm = resourceForm.bindFromRequest();
if(filledForm.hasErrors()){
return badRequest(filledForm.errorsAsJson());
}
User user = filledForm.get();
Map emailMap = new HashMap<>();
emailMap.put("email" , user.email);
List<User> existingUser = service.where(emailMap);
if(existingUser.size() != 0){
return JsonResponse.JsonMessage(BAD_REQUEST , "This Email is already registered");
}else{
user.status = getStatus(DORMANT);
user.save();
UserRegistration registration = new UserRegistration(user);
registration.save();
Email email = EmailDispatcher.buildEmail(ACTIVATION , user.email , registration.link);
mailerClient.send(email);
}
return ok(Json.toJson(user));
}
我的电子邮件配置设置为:
play.mailer{
host = "smtp.gmail.com"
port = 465
ssl = yes
user = "example.dev@gmail.com"
password = password
}
在我的Controller中调用mailerClient.send(email)
会导致抛出以下异常:
[error] a.a.ActorSystemImpl - Uncaught fatal error from thread [application-akka.actor.default-dispatcher-2] shutting down ActorSystem [application]
java.lang.NoSuchMethodError: play.api.PlayConfig.getOptional(Ljava/lang/String;Lplay/api/ConfigLoader;)Lscala/Option;
at play.api.libs.mailer.CommonsMailer.instance$lzycompute(MailerPlugin.scala:92)
at play.api.libs.mailer.CommonsMailer.instance(MailerPlugin.scala:88)
at play.api.libs.mailer.CommonsMailer.send(MailerPlugin.scala:109)
at play.api.libs.mailer.MailerClient$class.send(MailerPlugin.scala:44)
at play.api.libs.mailer.CommonsMailer.send(MailerPlugin.scala:83)
at controllers.api.UserController.create(UserController.java:57)
at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$6$$anonfun$apply$6.apply(Routes.scala:242)
at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$6$$anonfun$apply$6.apply(Routes.scala:242)
at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:157)
at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:156)
我使用的是Mailer 3.0.1版,我的build.sbt如下:
name := """API"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"mysql" % "mysql-connector-java" % "5.1.16",
"de.svenkubiak" % "jBCrypt" % "0.4",
"com.typesafe.play" %% "play-mailer" % "3.0.1"
)
我一直无法在其他地方找到类似的问题
答案 0 :(得分:3)
将您的版本更改为5.0.0-M1
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"mysql" % "mysql-connector-java" % "5.1.38",
"de.svenkubiak" % "jBCrypt" % "0.4",
"com.typesafe.play" %% "play-mailer" % "5.0.0-M1"
)
我刚刚从这几分钟就解决了这个问题,而你迟到了1个版本,有4.0.0-M1和新版本4.0.0用于播放2.4,但5.0.0-M1用于播放2.5, play-mailer从26天前开始从今天起更新。
编辑: 发布的5.0.0版本可以使用它:
"com.typesafe.play" %% "play-mailer" % "5.0.0"