提问人:Xon Fa 提问时间:10/30/2023 更新时间:10/30/2023 访问量:43
AWS SES SMTP AuthenticationFailedException:220 准备启动 TLS
AWS SES SMTP AuthenticationFailedException: 220 Ready to start TLS
问:
我按照文档 (https://docs.aws.amazon.com/zh_cn/ses/latest/dg/send-email-smtp.html) 中的说明创建 SMTP 凭据并下载了凭据的.csv文件;但是当我在 Java 代码中使用 SMTP 发送电子邮件 (Open JDK 1.8) 时,我收到了异常。
我的依赖关系:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
我的代码:
private static final String HOST = "email-smtp.us-west-2.amazonaws.com";
private static final String PORT = "587";
private static final String USER_NAME = "SMTP user name in credentials.csv";
private static final String PASSWORD = "SMTP password in credentials.csv";
public static void main(String[] args) throws UnsupportedEncodingException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host", HOST);
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(USER_NAME, PASSWORD);
}
});
MimeMessage message = new MimeMessage(session);
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]"));
message.setSubject("AWS SES SMTP Email");
message.setContent("<p>Hello, AWS SES SMTP<a href=\"https://www.google.com\">click btn</a></p>", "text/html;charset=UTF-8");
Transport.send(message);
}
异常日志:Exception in thread "main" javax.mail.AuthenticationFailedException: 220 Ready to start TLS
我应该如何解决?
答:
0赞
Xon Fa
10/30/2023
#1
此问题已解决
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
评论
1赞
Craig Taylor
10/30/2023
Xon Fa - 下次,你能不能附上一条评论,提到为什么这是一个解决方案?它将在将来寻找类似问题时帮助其他人。根据我之前在这方面的工作,我敢打赌您连接到的邮件服务器在 TLS 协议方面存在问题(TLSv1.1 最近被弃用/从 JVM 中删除,如果这是它最初协商的方式 - 它可能会导致这样的错误(堆栈跟踪会突出显示它))。
评论