java 17 logback SMTPAppender: AuthenticationFailedException: 220 准备启动 TLS

java 17 logback SMTPAppender: AuthenticationFailedException: 220 Ready to start TLS

我有以下带有 SMTPAppender 的 logback 配置,在 Java13 上运行良好,所有邮件都通过 AWS SES 发送,没有任何问题。

   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
    <smtpHost>email-smtp.us-east-1.amazonaws.com</smtpHost>
    <smtpPort>587</smtpPort>
    <username>name</username>
    <password>password</password>

    <to>${TO}</to>
    <from>${FROM}</from>
    <subject>${HOSTNAME}: %logger{30} -</subject>

    <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%date %-5level %logger{35} -[%t, U_%X{userId}, T_%X{traceId}]- %message%n</pattern>
    </layout>
    <asynchronousSending>true</asynchronousSending>
    <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
        <bufferSize>1</bufferSize>
    </cyclicBufferTracker>
</appender>

但是当我们设置Java17时,邮件没有发送,调试模式显示如下错误:

-ERROR in ch.qos.logback.classic.net.SMTPAppender[EMAIL] - Error occurred while sending e-mail notification. javax.mail.AuthenticationFailedException: 220 Ready to start TLS

at javax.mail.AuthenticationFailedException: 220 Ready to start TLS

at  at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at  at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
at  at javax.mail.Service.connect(Service.java:388)
at  at javax.mail.Service.connect(Service.java:246)
at  at javax.mail.Service.connect(Service.java:195)
at  at javax.mail.Transport.send0(Transport.java:254)
at  at javax.mail.Transport.send(Transport.java:124)
at  at ch.qos.logback.core.net.SMTPAppenderBase.sendBuffer(SMTPAppenderBase.java:388)
at  at ch.qos.logback.core.net.SMTPAppenderBase$SenderRunnable.run(SMTPAppenderBase.java:670)
at  at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at  at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at  at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at  at java.base/java.lang.Thread.run(Thread.java:833)

你有什么解决这个问题的想法吗?

我们通过更换

来解决这个问题
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>javax.mail-api</artifactId>
    <version>1.6.2</version>
</dependency>

<dependency>
   <groupId>com.sun.mail</groupId>
   <artifactId>jakarta.mail</artifactId>
   <version>1.6.7</version>
</dependency>