我知道在很多不同的地方已经多次询问过这个问题,但由于某种原因,我似乎无法让它发挥作用。我意识到问题是什么,我似乎无法弄清楚yaml语法或类似的东西。
我使用Grails 3和#34; mail"插件(2.0.0.RC6)。
以下是我的application.yml:
的片段grails:
serverURL: <url>
mail:
host: <host>
port: 587
username: <username>
password: <password>
props:
? "mail.smtp.auth" : true
? "mail.smtp.starttls.enable" : true
? "mail.smtp.starttls.required" : true
? "mail.smtp.socketFactory.class" : "javax.net.ssl.SSLSocketFactory"
? "mail.smtp.socketFactory.fallback" : false
? "mail.smtp.port" : 587
我尝试了许多引号组合而没有运气。 ?
代替-
表示地图,这是我想要的。
如果有帮助,以下是具体的错误消息:
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:130)
at grails.plugins.mail.MailService.sendMail(MailService.groovy:53)
at grails.plugins.mail.MailService.sendMail(MailService.groovy:57)
at website.UserController.register(UserController.groovy:60)
... 3 common frames omitted
这是运行Postfix的自定义邮件服务器(第一次设置它)。我可以连接到它并使用Thunderbird发送邮件。 Thunderbird使用STARTTLS和端口587进行连接。据我所知,我还没有能够做到SSL / TLS。
更新
我删除了工厂配置并修复了yaml地图的内容。现在我又收到了另一个错误。
grails:
serverURL: https://test.neonorb.com
mail:
host: test.neonorb.com
port: 587
username: neonorb
password: pass
props:
mail.smtp.starttls.enable: true
mail.smtp.port: 587
以下是例外:
unable to find valid certification path to requested target. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:130)
at grails.plugins.mail.MailService.sendMail(MailService.groovy:53)
at grails.plugins.mail.MailService.sendMail(MailService.groovy:57)
at website.UserController.register(UserController.groovy:60)
... 3 common frames omitted
Caused by: javax.mail.MessagingException: Could not convert socket to TLS
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2046)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:711)
at javax.mail.Service.connect(Service.java:366)
... 7 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:598)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:525)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2041)
... 9 common frames omitted
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
... 12 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
... 12 common frames omitted
根据Google的说法,这是因为证书是自签名的,Java并不信任它。我的证书不是自签名的,而是来自我们的加密。