当我尝试从scala Playmework发送邮件时,我收到了以下错误,
[ERROR] [10/10/2013 13:31:16.263] [play-akka.actor.default-dispatcher-75] [TaskInvocation] Sending the email to the following server failed : smtp.gmail.com:25
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at com.typesafe.plugin.CommonsMailer.send(MailerPlugin.scala:241)
at com.typesafe.plugin.MailerBuilder$class.sendHtml(MailerPlugin.scala:204)
at com.typesafe.plugin.CommonsMailer.sendHtml(MailerPlugin.scala:215)
at models.SignUpProcess$$anonfun$models$SignUpProcess$$sendEmail$1.apply$mcV$sp(SignUpProcess.scala:261)
at akka.actor.DefaultScheduler$$anon$8.run(Scheduler.scala:193)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137)
at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 12 more
如何解决此错误?
SignUpProcess.scala
private def sendEmail(subject: String, recipient: String, bodyString:Html) {
import scala.concurrent.duration._
import play.api.libs.concurrent.Execution.Implicits._
Akka.system.scheduler.scheduleOnce(1 seconds) {
val mail = use[MailerPlugin].email
mail.setSubject(subject)
mail.addRecipient(recipient)
mail.addFrom("innodeagcm@gmail.com")
println(bodyString)
mail.sendHtml(bodyString.toString)
}
}
application.conf
smtp.host = smtp.gmail.com
smtp.port = 465
smtp.ssl = true
smtp.tls = no
smtp.user = "companymail@gmail.com"
smtp.password = "mypassword"
答案 0 :(得分:16)
1。以下是 GMail 的工作配置:
smtp.host=smtp.gmail.com
smtp.port=587
smtp.ssl=yes
smtp.user="me@gmail.com"
smtp.password="myPassword"
您必须使用端口587 (并激活 SSL )
2。同时确保未激活双因素身份验证(否则您必须生成新的应用程序密码)
3。连接失败的另一个原因是:它可能看起来像是可疑连接。
请检查从您的帐户收到的来自谷歌的邮件,以确保谷歌没有阻止该连接(如果播放是在另一个国家托管,而不是您手动连接的国家/地区)
答案 1 :(得分:7)
smtp:port = 587对我不起作用。但是465端口为我工作。
smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=true
答案 2 :(得分:2)
您应首先在Google中启用访问安全性较低的应用,如上面的答案所示。现在将端口更改为465并设置ssl = true。或者你可以设置port = 587和tls = true。这是因为端口465用于SSL,端口587用于TLS,根据官方文档。
port = 465
ssl = true
**请注意,使用ssl = true的port = 587将无效
答案 3 :(得分:0)
如果您认为所有设置都正确,但仍然收到此消息;我建议看一下附件。我发送了一个 .JAR 文件,gmail服务器不允许您附加,因此它拒绝了我的电子邮件。我不得不将文件重命名为 .JARA 以使其正常工作。
答案 4 :(得分:0)
我已阅读此处的所有评论,并获得了成功。出于这个原因:这是我的代码,它可以完美运行。
smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=true
smtp.auth=true
smtp.user="xxxxxx@gmail.com"
smtp.password=xxxxxxx