I'm having this problem when sending an email with Java 8 and JavaMail 1.5:
EDIT: Java 1.8.0_301 (but also 1.8.0.192) and Javamail 1.5.0
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1764)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1523)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:313)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
I only have the problem with JavaMail 1.5, I don't have the problem when using JavaMail 1.6, nor when using JavaMail 1.4 (up to 1.4.1).
I would go on using JavaMail 1.4.1 or I would happily upgrade to JavaMail 1.6, but unfortunately I cannot (due to backwards Java compatibility).
EDIT: we must maintain compatibility with older versions of Websphere which use java 1.6. Obviously in this case the application won't send mail with TLS1.2 and would only support older protocol versions or sending via port 25 through a connector
My code is the following:
Properties props = new Properties();
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.host", "xxx");
props.put("mail.from", "xxxxxxxxxxx");
props.put("mail.smtp.port", "465");
Session session = Session.getInstance(props);
Authenticator auth = new javax.mail.Authenticator() {protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxxxxxxxxxxx","xxxxxxxxxxxx");}};
session = Session.getInstance(props, auth);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress("xxxxxxxxx"));
message.setRecipients(Message.RecipientType.TO, "yyyyyyyyyyy");
message.setSubject("TEST");
message.setText("Dear Tester,...... ");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
e.printStackTrace(output);
output.println(e.getMessage());
}
Using JavaMail 1.6 it works, when using JavaMail 1.5 it doesn't. With JavaMail 1.5, I solve the problem only if I force the protocol version, this way:
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
I'd rather not use this solution, in favor of a more generic and standard solution. Anyone have any ideas?