我正在尝试在Play中发送电子邮件!框架v 2.1.1。
在build.scala中我有:
"com.typesafe" %% "play-plugins-mailer" % "2.1.0"
在conf / application.conf中我有:
smtp.host=smtp.gmail.com
smtp.port= "587"
smtp.ssl=true
smtp.tls=true
smtp.user="dylanrboudro@gmail.com"
smtp.password="xxxxxx"
我也试过smtp.port =“465”
发送电子邮件的方法是:
public void Email() {
MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
mail.setSubject("test");
mail.addRecipient("dylanrboudro@gmail.com");
mail.addFrom("DevOpsNotifications@gmail.com");
String body = "this is the first email sent by the devops requestor";
mail.sendHtml(body);
我收到此错误:
[RuntimeException: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587]
这个堆栈跟踪:
! @6f9o6gmj8 - Internal server error, for (POST) [/request] ->
play.api.Application$$anon$1: Execution exception[[RuntimeException: org.apache.
commons.mail.EmailException: Sending the email to the following server failed :
smtp.gmail.com:587]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_
2.10.jar:2.1.1]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_
2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$ha
ndle$1.apply(PlayDefaultUpstreamHandler.scala:144) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$ha
ndle$1.apply(PlayDefaultUpstreamHandler.scala:140) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise
.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise
.scala:113) [play_2.10.jar:2.1.1]
java.lang.RuntimeException: org.apache.commons.mail.EmailException: Sending the
email to the following server failed : smtp.gmail.com:587
at play.libs.F$Promise$6.apply(F.java:401) ~[play_2.10.jar:2.1.1]
at scala.concurrent.Future$$anonfun$map$1.liftedTree2$1(Future.scala:253
) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scal
a-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scal
a-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29) ~[scala-
library.jar:na]
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(Bat
chingExecutor.scala:67) ~[akka-actor_2.10.jar:na]
Caused by: org.apache.commons.mail.EmailException: Sending the email to the foll
owing server failed : smtp.gmail.com:587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242) ~[comm
ons-email-1.2.jar:1.2]
at org.apache.commons.mail.Email.send(Email.java:1267) ~[commons-email-1
.2.jar:1.2]
at com.typesafe.plugin.CommonsMailer.send(MailerPlugin.scala:242) ~[play
-plugins-mailer_2.10-2.1.0.jar:2.1.0]
at com.typesafe.plugin.MailerBuilder$class.sendHtml(MailerPlugin.scala:2
04) ~[play-plugins-mailer_2.10-2.1.0.jar:2.1.0]
at com.typesafe.plugin.CommonsMailer.sendHtml(MailerPlugin.scala:215) ~[
play-plugins-mailer_2.10-2.1.0.jar:2.1.0]
at models.V1Project.Email(V1Project.java:211) ~[na:na]
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.g
mail.com, port: 465
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391) ~
[mail-1.4.1.jar:1.4.1]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:41
2) ~[mail-1.4.1.jar:1.4.1]
at javax.mail.Service.connect(Service.java:310) ~[mail-1.4.1.jar:1.4.1]
at javax.mail.Service.connect(Service.java:169) ~[mail-1.4.1.jar:1.4.1]
at javax.mail.Service.connect(Service.java:118) ~[mail-1.4.1.jar:1.4.1]
at javax.mail.Transport.send0(Transport.java:188) ~[mail-1.4.1.jar:1.4.1
]
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.7.0_
07]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI
mpl.java:69) ~[na:1.7.0_07]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja
va:339) ~[na:1.7.0_07]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket
Impl.java:200) ~[na:1.7.0_07]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:182) ~[na:1.7.0_07]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) ~[na:1.7.0
_07]
任何人都有任何想法?非常感谢!
答案 0 :(得分:1)
您需要从smtp.port设置中删除引号。
它应该是smtp.port = 587
。
我没有使用smtp.password
字段的引号,它对我有效。
答案 1 :(得分:0)
以下示例应用可满足您的需求: https://github.com/jamesward/play-emailer
也许尝试该应用程序,看看它是否有效。如果没有,那么您的问题可能是您的网络不允许出站连接。