0

我使用 SMTPAppender 进行了以下 logback 配置,该配置在 Java 13 上运行良好,并且所有邮件都通过 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>

但是当我们设置 Java 17 时,邮件没有发送,并且调试模式显示以下错误:

-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)

您对如何解决此问题有任何想法吗?

4

1 回答 1

1

我们通过替换来解决这个问题

<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>
于 2021-11-17T13:54:28.300 回答