Framework/Spring

[ERROR]EC2 Gmail SMTP 발송 오류

  • -
반응형

최근 Gmail을 이용해 메일을 보내는 기능을 추가했는데 로컬 단계에서 잘 작동하는 기능이 클라우드 서버에 올라가면 안되는 현상이 발생했습니다.

처음에는 AWS의 보안 설정을 의심했으나 Smtp port를 인바운드에 등록해도 해결되지 않았습니다.

로그에 찍힌 에러 메세지를 키워드로 원인을 찾기 시작했습니다.

 

could not convert socket to TLS

 

결론은 Gmail TLS 버전과 관련이 있었습니다.

기존 메일 서비스에는 TLS 보안인증이 활성화(prop.put("mail.smtp.starttls.enable", "true"))가 되어있습니다.

구글에서는 TLS 1.0, 1.1의 지원을 종료하겠다는 내용을 발표했는데 현재 사용 중인 javax.mail 라이브러리의 버전에서 TLS 1.1 이하를 기본으로 사용하는 것을 의심했고 TLS .1.2 버전을 강제하도록 했습니다.

private Session init() {
    Properties prop = System.getProperties();
    prop.put("mail.smtp.starttls.enable", "true");
    prop.put("mail.smtp.host", "smtp.gmail.com");
    prop.put("mail.smtp.auth", "true");
    prop.put("mail.smtp.port", "587");

    Authenticator auth = new EmailAuth();

    return Session.getDefaultInstance(prop, auth);
}

 

아래와 같이 옵션을 추가하고나니 메일이 정상적으로 전송되는 것을 확인했습니다.

prop.put("mail.smtp.ssl.trust", "smtp.gmail.com");
prop.put("mail.smtp.ssl.protocols", "TLSv1.2");

 

참고문서
 

Cannot send email from EC2 instance on port 587

I have written a mail service for our flask application that uses Celery and RabbitMQ to send emails (using gmail). I have got the celery consumer and producer communicating okay but I cannot get t...

serverfault.com

 

[Java Mail] Could not convert socket to TLS; 문제 해결

문제 서버에서 javax email을 활용해 구글 이메일을 전송 할 때 아래와 같은 에러가 발생 했습니다. org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Co

shanepark.tistory.com

 

How to verify the TLS version used in javax.mail.*;

When connecting to an SMTP server using javax.mail , how can I make sure that the version of TLS is v1.2 or higher. I am using Java version 8 (update 162).

stackoverflow.com

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.