grails - Grails 3邮件:必须先发出STARTTLS命令

标签 grails yaml jakarta-mail grails-3.0 starttls

我知道这个问题已经在许多不同的地方被问过很多次,但是由于某种原因,我似乎无法使其正常工作。我意识到问题出在哪里,我似乎无法弄清楚yaml语法或类似的简单内容。

我正在使用带有“邮件”插件(2.0.0.RC6)的Grails 3。

这是我的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

我尝试了很多没有运气的引号组合。 ?而不是-表示一张 map ,这就是我想要的。

如果有帮助,这是特定的错误消息:
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 map 内容。现在我又遇到了另一个错误。
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

这是异常(exception):
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不信任它。我的证书不是自签名的,而是由Let's Encrypt制作的。

最佳答案

Get rid of the socket factory properties,它们早已过时了。

关于grails - Grails 3邮件:必须先发出STARTTLS命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36659487/

相关文章:

java - JRebel 从 Grails 项目中删除所有日志记录

Grails 3.0.1 - 如何在 application.yml 中配置 grails.gorm.default.constraints

java - 使用 snakeYaml 在根部解析带有映射的 YAML 文档

java - 想要在android中使用JavaMailAPI发送电子邮件。该代码工作正常并且所有信息都显示在日志中

java - 显示数据时grails删除[]

grails - 无法解析配置 ':profile'的所有依赖项

java - 是否可以使用非 void 的 setter 反序列化 yaml 文档?

c# - Azure DevOps Pipeline 不从 Net Core 3.1 应用程序生成单个文件 exe

java - 是否有任何 Java API 可以读取 Exchange 数据库或 Outlook 邮箱中已删除的邮件?

java - Wildfly -9 javax.mail 不工作