Good morning,
I'm trying to send a mail in a java application running on Ubuntu with jakarta.mail-api version 2.1.2 and openjdk version 11.0.20.1
but I obtain following exception:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Here's my code:
Properties props = new Properties();props.put("mail.smtp.host", "smtp.office365.com"); //SMTP Hostprops.put("mail.smtp.port", "587"); //TLS Portprops.put("mail.smtp.auth", "true"); //enable authenticationprops.put("mail.smtp.starttls.enable", "true"); //enable STARTTLSprops.put("mail.smtp.ssl.protocols", "TLSv1.2");props.put("mail.debug", "true");Authenticator auth = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("abc@xxxx.com", "yyyy"); }};Session session = Session.getInstance(props, auth);try { MimeMessage msg = new MimeMessage(session); msg.addHeader("Content-type", "text/HTML; charset=UTF-8"); msg.addHeader("format", "flowed"); msg.addHeader("Content-Transfer-Encoding", "8bit"); msg.setFrom(new InternetAddress("abc@xxxx.com")); msg.setReplyTo(InternetAddress.parse("abc@xxxx.com", false)); msg.setSubject("Mail Subject"); msg.setText("body", "UTF-8"); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("me@xxxx.com", false)); Transport.send(msg); log.info("Email Sent Successfully!!");} catch (Exception e) { log.error("Error",e);}
Same code works well on my Windows 11 machine with java version 11.0.19 installed. Any suggestion?
UPDATE:As suggested by dave_thompson_085 I've changed
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
in
props.put("mail.smtp.ssl.protocols", "TLSv1.3");
but exception remains the same.
Checking java.security I've found:
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \include jdk.disabled.namedCurves
after commenting these three lines Exception become:
javax.mail.AuthenticationFailedException: nullat javax.mail.Service.connect(Service.java:306) ~[mail-1.4.jar:1.4]
after removing only TLSv1, TLSv1.1, I catch always:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)