[MailAuthenticationException/500]nested exception is org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException

2019. 10. 17. 20:57에러해결법

SMTP를 이용한 메일보내기를 구현하던 중 다음과 같은 에러가 발생했다.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvj 534-5.7.14 pJe9OoDTqtD5SMksyod8U7i06a04--LEBkE7XpGzlxE2J1zEwqsC4hoCDbXx3U_YrdpqH7 534-5.7.14 y94ojksNzsIbNt1yyOBhPqYqYs3uq3W6WLtusMEThTtHrVZpife_yAWHXDyGqg> Please 534-5.7.14 log in via your web browser and then try again. 534-5.7.14 Learn more at d19sm4840195pjz.5 - gsmtpjavax.mail.AuthenticationFailedException

위와같은 에러가 발생했을 때 2가지 케이스를 생각해 볼 수 있다.

1. smtp 설정한 계정의 아이디나 비밀번호가 틀렸을 경우

2. smtp 설정한 계정의 stmp기능을 허용해주지 않았기 때문

1번 같은 경우는 아이디와 비밀번호만 변경해주면 해결하지만 2번일 경우 조금 복잡해진다.

본인은 구글계정을 smtp로 사용했기 때문에 구글을 기준으로 해결법을 작성하겠다.


1. 구글 SMPT 허용

 

- 우선 Gmail에 접속하고 우편함에서 설정아이콘 - 설정을 클릭해 들어간다.

 

- 전달 및 POP/IMAP를 클릭하고 IMAP액세스를 위와같이 설정한다.

 

2.  보안 액세스 설정

- SMTP를 설정 후 구글계정 설정 - 보안 을 들어가면 위와같은 보안수준이 낮은 앱의 액세스가 뜬다.

이것을 사용모드를 눌러 보안수준이 낮은 앱의 엑세스를 허용해준다.

이 후, 서버를 RESTART 후 실행하면 SMTP기능이 잘 되는 것을 볼 수 있다.