java - 如何正确设置 javamail 以使用 STARTTLS?

标签 java smtp jakarta-mail starttls

在设置 session 时,我设置了 starttls.enable 和 .required 属性,但是当连接发生时,根据文档,它应该会失败:

mail.smtp.starttls.enable boolean If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. Defaults to false." http://javamail.kenai.com/nonav/javadocs/com/sun/mail/smtp/package-summary.html

props = new Properties();
props.put("mail.smtps.host", MAILSERV);
props.put("mail.smtps.socketFactory.port", 465);
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.port", 465);
props.put("mail.smtps.socketFactory.fallback", "false");
props.put("mail.smtps.socketFactory.class","utils.DummySSLSocketFactory");
props.put("mail.smtps.quitwait", "false");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
Session session = Session.getInstance(props, authenticator);  


transport = session.getTransport("smtps");
transport.connect(mailServer, port, username, password);
transport.sendMessage(message, message.getAllRecipients());

那么我做错了什么,让我在服务器不支持 Starttls 时使用它?

最佳答案

我在 STARTTLS 方面遇到的问题是由我获得安全传输引起的:

transport = session.getTransport("smtps");

将其更改为“smtp”后,我能够使用 STARTTLS。

关于java - 如何正确设置 javamail 以使用 STARTTLS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15619349/

相关文章:

java - 如何用java发送ZOHO SMTP服务器邮件?

java - 无法从 GAE 的 java mail APi 发送邮件

c# - 如何使用 .NET 接收邮件?

c# - 使用 C# 通过 Gmail SMTP 服务器发送电子邮件

java - 如果至少有一个有效收件人,则发送邮件

java - 未从查询字符串获取值

java - 这种技术会阻止 Java 进行垃圾收集吗?

java - 将自定义参数添加到 spring mvc Controller

java - SonarQube 覆盖范围缺少 Jacoco 报告覆盖的一些行

java - 将属性文件放入 JTree 而不仅仅是显示它