관리 메뉴

Just Do it

[스프링/STS] DEBUG SMTP: could not connect to host "smtp.naver.com", port: 465, response: -1 & javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) & javax.net.ssl.SSLException: Unsupp.. 본문

신입 개발자가 되기 위해 공부했던 독학 자료들/에러 해결 모음

[스프링/STS] DEBUG SMTP: could not connect to host "smtp.naver.com", port: 465, response: -1 & javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) & javax.net.ssl.SSLException: Unsupp..

Seojoo21 2022. 3. 19. 20:14

첫번째 에러: 
DEBUG SMTP: could not connect to host "smtp.naver.com", port: 465, response: -1

 

개인 프로젝트 중 회원 가입 시 입력한 이메일 주소로 인증 번호를 보내주는 기능을 구현하고자 SMTP Server를 이용한 메일 전송 방법을 공부하고 마지막 테스트를 하던 중 아래와 같은 에러를 만났다.

 

DEBUG SMTP: EOF: [EOF]

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.naver.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.naver.com, port: 465, response: -1; message exception details (1) are:

Failed message 1:

DEBUG SMTP: could not connect to host "smtp.naver.com", port: 465, response: -1

 

 

알고보니 root-context.xml에 메일 설정을 위해 등록한 mailsender 빈에 네이버의 SMTP 서버포트가 잘못되어 있었다.

네이버의 SMTP 서버포트 번호는 465가 아닌 587이었고 또한 <props>에 추가로 SSL 설정을 해줘야만 했다.

<prop key="mail.smtp.ssl.enable">true</prop>

 

그래서 root-context.xml에서 빈 설정을 수정하였다. 

 

* 수정 전)

 

* 수정 후) 

그러나 또다른 에러가 발생했다....

 

두번째 에러:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) 

 

또 다른 에러가 발생했다. 포트번호를 587이 아닌 465로 해도 포트번호만 바뀔 뿐 동일한 에러가 나타났다.

이로써 먼저 등장했던 "DEBUG SMTP: could not connect to host "smtp.naver.com", port: 465, response: -1" 이 에러는 <props> 에 SSL 설정을 하지 않아 발생한 에러로 보였다. 

 

javax.mail.MessagingException: Could not connect to SMTP host: smtp.naver.com, port: 587;

  nested exception is:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

javax.mail.MessagingException: Could not connect to SMTP host: smtp.naver.com, port: 465;

nested exception is:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

 

찾아보니...

-------------------------

위의 에러는 server와 client 간에 사용하는 SSL/TLS 버전이 맞지 않기 때문에 발생합니다.

server가 TLS 1.2 버전만 사용할 때 Java의 경우 JDK 1.8 부터 TLS 1.2 가 기본 버전이므로 문제가 없지만, 이전 JDK 버전을 사용하는 client의 경우는 예외가 발생하게 됩니다.

 

JDK 1.8 버전으로 업그레이드하면 문제가 해결되지만.... (생략) 

(출처: https://freestrokes.tistory.com/68)

----------------------------------------- 

엥....? JDK 1.8로 프로젝트를 하고 있는데 저 에러가 발생했다니 너무 당황스러웠다. 해결을 위해 구글링을 하던 중 스택오버플로우에서 아래 댓글을 보았는데...

(출처:https://stackoverflow.com/questions/67899129/postfix-and-openjdk-11-no-appropriate-protocol-protocol-is-disabled-or-cipher)

 

읽어보니 pom.xml에 설정한 javax.mail 버전을 바꾸면 되는 것 같아서 시도해보았다.  

그래서 기존 1.4.7 버전을 주석처리하고 1.6.2 버전을 넣어보았다. 이 과정에서 Maven 내에서 기존 javax 1.4.7 와 충돌하는지 콘솔창에 계속 오류가 뜨길래 STS 를 끄고 m2에서 repository를 모두 삭제한 후 다시 STS 켜서 Maven 업데이트를 해주었다.  

 

그랬더니 또 다른 에러가 발생했다......

 

세번째 에러:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

세번째 에러는 다음과 같았다. 

 

Failed message 1:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.naver.com, port: 587;

  nested exception is:

javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

 

구글에 검색해보니 아래 글을 볼 수 있었다.

(출처: http://daplus.net/java-인식-할-수없는-ssl-메시지-일반-텍스트-연결-예외/)

 

올바른  포트 번호를 사용하지 않았을 것이라고 해서 포트번호를 587에서 처음 시도했던 465로 다시 변경해보았다. 

그랬더니 마침내 해결 !!!!!!! 테스트 메일도 잘 들어왔다!!! 

 

 

참고 사이트: https://okky.kr/article/1155391

https://www.lesstif.com/system-admin/java-sslhandshakeexception-29590407.html

https://bug41.tistory.com/128