在设置 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/