java 邮件 aws smtp: javax.mail.AuthenticationFailedException: 220 准备启动 TLS

java mail aws smtp: javax.mail.AuthenticationFailedException: 220 Ready to start TLS

我已经为 smtp appender 配置了以下属性。相同的配置在本地工作正常但在 AWS 上出错

log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.BufferSize=20
log4j.appender.email.SMTPHost=email-smtp.us-east-1.amazonaws.com
log4j.appender.email.SMTPUsername=<username>
log4j.appender.email.SMTPPassword=<password>
log4j.appender.email.SMTPPort=587
log4j.appender.email.From=<from@email>
log4j.appender.email.To=<to@email>
log4j.appender.email.Subject=<Subjec>
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%d %-5p [%t] (%c{1}:%L) - %m%n
log4j.appender.email.SMTPDebug=true
log4j.appender.email.EnableSsl=true
log4j.appender.email.smtp.starttls.enable=true
log4j.appender.email.smtp.auth=true
log4j.appender.email.TLS=true

解决方法:我已经使用了 1.6.4 版本的 mailapi 和 smtp jar。

替换

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