使用Play Framework 2.2时使用Play-EasMail问题2.2
-
21-12-2019 - |
题
我使用下面的conf来通过play-easymail在Play v2.2中发送电子邮件 - 我没有看到我的代码中抛出的任何异常,我已经尝试了本地SMTP服务器以及SMTP服务Gmail。我无法收到电子邮件(它不在任何垃圾邮件文件夹中)。对此故障排除(除了检查本地SMTP服务器日志之外)的任何建议都将得到理解。 通过Application.config文件导入SMTP配置。
conf
# SMTP mailer settings
smtp {
# enable mocking - disable this for production
mock=true
# SMTP server
# (mandatory)
# defaults to gmail
host=smtp.gmail.com
# SMTP port
# defaults to 25
port=587
# Use SSL
# for GMail, this should be set to true
ssl=true
#tls=true
# authentication user
# Optional, comment this line if no auth
# defaults to no auth
user=correctEmail@gmail.com"
# authentication password
# Optional, comment this line to leave password blank
# defaults to no password (or use (two way) hash the pwd and get the pwd from the two way hash)
password=correctPwd
}
.
测试代码
import com.feth.play.module.mail.Mailer;
import com.feth.play.module.mail.Mailer.Mail.Body;
//email method: emailAddress passed is correct
try {
final Body body = new Body("test email");
Mailer.getDefaultMailer().sendMail("metrics email | it works!",
body, emailAddress);
}
catch (Exception e) {
Logger.info("exception while sending email {}", e);
e.printStackTrace();
}
. 解决方案
是试验错误。我必须在conf文件中设置mock等于false。在这种变化之后,我能够发送电子邮件。
mock=false
. 不隶属于 StackOverflow