我正在使用带有Grails 3.0.7的grails邮件插件(2.0.0.RC2)。这是我的配置:
mail:
host: smtp.gmail.com
port: 465
username: myuser@gmail.com
password: myPassword
props:
- mail.debug: true
- mail.smtp.auth: true
- mail.smtp.socketFactory.port: 465
- mail.smtp.socketFactory.class: javax.net.ssl.SSLSocketFactory
- mail.smtp.socketFactory.fallback: false
当我尝试发送测试邮件时,出现以下错误:
Caused by: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:131) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:55) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:59) ~[mail-2.0.0.RC2.jar:na]
at com.eduspace.ClassroomController.$tt__index(ClassroomController.groovy:13) ~[main/:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.7.jar:3.0.7]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.7.jar:3.0.7]
... 9 common frames omitted
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972) ~[javax.mail-1.5.1.jar:1.5.1]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656) ~[javax.mail-1.5.1.jar:1.5.1]
at javax.mail.Service.connect(Service.java:345) ~[javax.mail-api-1.5.1.jar:1.5.1]
... 15 common frames omitted
我在日志中看不到其他调试信息。我将根记录器设置为INFO,因此应该输出所有内容。我已经验证我可以telnet到smtp.gmail.com端口465,所以这不是问题。我已经读过其他人在使用SSL时遇到问题,但是通常会有一些调试信息表明存在SSL问题而且我没有得到类似的信息。
答案 0 :(得分:7)
我使用的配置略有不同,工作正常:
grails:
mail:
host: "smtp.gmail.com"
port: 465
username: "<username>@gmail.com"
password: "<password>"
props:
mail.smtp.auth: "true"
mail.smtp.socketFactory.port: "465"
mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"
mail.smtp.socketFactory.fallback: "false"
邮件配置位于 grails 占位符内部,我没有像您的示例中那样使用破折号。也许这对你有帮助。
答案 1 :(得分:4)
由于配置错误,这可能是错误的,但是这个确切错误消息的原因之一是gmail配置。为避免垃圾邮件,gmail已开始阻止来自不符合最新安全准则的应用程序的访问。
避免此错误的一种简单方法是转到您的Gmail帐户并允许安全性较低的应用.- https://www.google.com/settings/security/lesssecureapps
答案 2 :(得分:0)
您的配置看起来不错。
这是我的工作正常:
grails {
mail {
host = "smtp.gmail.com"
'default' {
from = "<username>@gmail.com"
}
port = 465
username = "<username>@gmail.com"
password = "<password>"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}