使用scala和play framwork发送电子邮件不会';不能在服务器上工作
当我尝试使用此配置从localhost发送带有scala和Playmework的邮件时:使用scala和play framwork发送电子邮件不会';不能在服务器上工作,scala,email,playframework,Scala,Email,Playframework,当我尝试使用此配置从localhost发送带有scala和Playmework的邮件时: play.mailer { host=smtp.gmail.com port=465 ssl=true user = "emaifortest@gmail.com" password = "password" debug=false mock=false from="emaifortest2013@gmail.com" } 此功能用于在发送邮件之前将用户保存在tempuse
play.mailer {
host=smtp.gmail.com
port=465
ssl=true
user = "emaifortest@gmail.com"
password = "password"
debug=false
mock=false
from="emaifortest2013@gmail.com"
}
此功能用于在发送邮件之前将用户保存在tempuser集合中:
def saveSendConfirmation = Action.async(parse.json) { implicit request =>
request.body.validate[TempUserForm.Data].fold(
form => Future.successful(BadRequest(Json.obj("message" -> "invalid data"))),
data => {
val firstName = data.firstName
val lastName = data.lastName
val email = data.email
val customerId = data.customerId
val communityId = data.communityId
val entityId = data.entityId
val roles = data.roles
val currentDate: DateTime = new DateTime()
val user = TempUser(Option(java.util.UUID.randomUUID), firstName, lastName, email, customerId, communityId, entityId, roles, Option(false), currentDate)
tempUserService.create(user).map {
case Right(_id) =>
val email = Email(
"Verification",
"<emaifortest2013@gmail.com>",
Seq(user.email),
attachments = Seq(),
bodyText = Some("A text message"),
bodyHtml = Some(
"""
<a href='http://5.189.165.188:9001/confirmation/""" + _id + """'>
"""))
mailerClient.send(email)
Ok(Json.toJson(Json.obj("_id" -> _id)))
case Left(error) => BadRequest(Json.toJson(Json.obj("message" -> error)))
}
})
}
答案就在这里
Caused by: javax.mail.AuthenticationFailedException:
...
Please log in via your web browser and then try again.
Learn more at https://support.google.com/mail/answer/78754
您可以从本地登录,因此看起来谷歌检查了IP或试图询问身份验证过程中的第二步。你需要阅读
我有类似的场景,并在谷歌帐户中使用“”选项,因此我可以从本地和服务器发送电子邮件 答案本身就显示出来了
Caused by: javax.mail.AuthenticationFailedException:
...
Please log in via your web browser and then try again.
Learn more at https://support.google.com/mail/answer/78754
您可以从本地登录,因此看起来谷歌检查了IP或试图询问身份验证过程中的第二步。你需要阅读
我有类似的场景,并在谷歌帐户中使用“”选项,因此我可以从本地和服务器发送电子邮件 没有错误堆栈跟踪,任何人都无法帮助您。但通过查看您的代码,我认为mailer中的成功/失败不会对您的响应产生任何影响。您使用的邮件程序是什么?若要获取错误,请将此->
mailerClient.send(email)
替换为此->Try(mailerClient.send(email))match{case Success=>{//do nothing}case Failure(ex)=>log.error(ex,“发送电子邮件失败”)}
@SarveshKumarSingh请检查更新这是在上述更改后获得的整个堆栈跟踪吗?我不认为是这样。这个问题太多噪音,有用的信息太少。没有错误堆栈跟踪,没有人能帮助你。但通过查看您的代码,我认为mailer中的成功/失败不会对您的响应产生任何影响。您使用的邮件程序是什么?若要获取错误,请将此->mailerClient.send(email)
替换为此->Try(mailerClient.send(email))match{case Success=>{//do nothing}case Failure(ex)=>log.error(ex,“发送电子邮件失败”)}
@SarveshKumarSingh请检查更新这是在上述更改后获得的整个堆栈跟踪吗?我不这么认为。这个问题太吵了,有用的信息太少。