scala 将电子邮件发送到以下服务器失败:smtp.gmail.com:25
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19292882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending the email to the following server failed : smtp.gmail.com:25
提问by Ramprasad
When I try to send a mail from scala Playmework, I got following error,
当我尝试从 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.apply$mcV$sp(SignUpProcess.scala:261)
at akka.actor.DefaultScheduler$$anon.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
How to solve this error?
如何解决这个错误?
SignUpProcess.scala
注册过程.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("[email protected]")
println(bodyString)
mail.sendHtml(bodyString.toString)
}
}
application.conf
应用程序配置文件
smtp.host = smtp.gmail.com
smtp.port = 465
smtp.ssl = true
smtp.tls = no
smtp.user = "[email protected]"
smtp.password = "mypassword"
回答by Julien D
1.Here is a working configuration for GMail:
1.这是GMail的工作配置:
smtp.host=smtp.gmail.com
smtp.port=587
smtp.ssl=yes
smtp.user="[email protected]"
smtp.password="myPassword"
You must use port 587(and so activate SSL)
您必须使用端口 587(因此激活SSL)
2.Also ensure that Two factor authentication is not activated(otherwise you must generate a new application password)
2.还要确保未激活双因素身份验证(否则您必须生成新的应用程序密码)
3.Another cause of connection fail : it can be seemed like a suspect connection.
3.连接失败的另一个原因:它看起来像是一个可疑的连接。
So check mails received from google on your account to ensure the connection has not been blocked by google (happens if play is hosted in another country than the one you are used to connect manually)
因此,请检查您帐户上从 google 收到的邮件,以确保连接未被 google 阻止(如果游戏托管在另一个国家/地区而不是您用于手动连接的国家/地区,则会发生这种情况)
回答by naveen dahiya
回答by Muhammed Zubairuddin
You should first enable the access in Google for less secure App as shown in the above answer. Now Change the port to 465 and set ssl=true. Or you can set port=587 and tls=true. This is because port 465 is for SSL and port 587 is for TLS according to the official documentations.
您应该首先在 Google 中启用安全性较低的应用程序的访问权限,如上述答案所示。现在将端口更改为 465 并设置 ssl=true。或者您可以设置 port=587 和 tls=true。这是因为根据官方文档,端口 465 用于 SSL,端口 587 用于 TLS。
port=465
ssl=true
端口=465
ssl=true
**Note that port=587 with ssl=true won't work
**注意 port=587 和 ssl=true 将不起作用
回答by Abhijith Kolanakuduru
If you feel all settings are correct, but still getting this message; I'd suggest to look at the attachments. I was sending a .JARfile which gmail servers won't allow you to attach and hence it was rejecting my email. I had to rename the file to .JARAto make it work.
如果您觉得所有设置都正确,但仍然收到此消息;建议看附件。我正在发送一个.JAR文件,gmail 服务器不允许您附加该文件,因此它拒绝了我的电子邮件。我必须将文件重命名为.JARA才能使其工作。
回答by Anthony Puitiza
I've read all comment to here and I've had success. For this reason: this is my code that It could work perfectly.
我已经阅读了这里的所有评论,我已经成功了。出于这个原因:这是我的代码,它可以完美地工作。
smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=true
smtp.auth=true
smtp.user="[email protected]"
smtp.password=xxxxxxx


