[에러 로그]Gmail SMTP 메일 전송 에러 로그

jyleever·2022년 5월 24일
0

Helpring 에러 로그

목록 보기
7/12

InternetAddress.parse NullPointerException

java.lang.NullPointerException: null
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:769) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:728) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:705) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at org.springframework.mail.javamail.MimeMessageHelper.parseAddress(MimeMessageHelper.java:735) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.MimeMessageHelper.setTo(MimeMessageHelper.java:621) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.MimeMailMessage.setTo(MimeMailMessage.java:109) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.SimpleMailMessage.copyTo(SimpleMailMessage.java:204) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:320) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:312) ~[spring-context-support-5.3.19.jar:5.3.19]
	at com.jy.helpring.service.mail.MailServiceImpl.sendMail(MailServiceImpl.java:49) ~[classes/:na]

원인

builder 패턴으로 mailVo 객체에 값을 생성하는 코드를 잘못 작성하여 수신 메일이 담기지 않아서 생긴 문제였다.
MailService에서 mailVo에 수신 메일 등 메일 관련 정보를 정상적으로 작성해주었다.

MailVo mailVo = MailVo.builder()
        .toAddress(memberEmail)
        .title(title)
        .message(message + tmpPassword)
        .fromAddress(fromAddress)
        .build();

SSLException

  nested exception is:
	javax.net.ssl.SSLException: Unsupported or unrecognized SSL message. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
  nested exception is:
	javax.net.ssl.SSLException: Unsupported or unrecognized SSL message; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
  nested exception is:
	javax.net.ssl.SSLException: Unsupported or unrecognized SSL message] with root cause
    javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
	at java.base/sun.security.ssl.SSLSocketInputRecord.handleUnknownRecord(SSLSocketInputRecord.java:451) ~[na:na]
	at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:175) ~[na:na]
	at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:111) ~[na:na]
	at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1506) ~[na:na]
	at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1416) ~[na:na]
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:456) ~[na:na]
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:427) ~[na:na]
	at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:602) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:376) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:214) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2160) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at javax.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.6.7.jar:1.6.7]
	at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:437) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:323) ~[spring-context-support-5.3.19.jar:5.3.19]
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:312) ~[spring-context-support-5.3.19.jar:5.3.19]
	at com.jy.helpring.service.mail.MailServiceImpl.sendMail(MailServiceImpl.java:48) ~[classes/:na]

SSL에 문제가 있는 것 같았다.
application.yml 설정 파일을 살펴봤다.

spring:
  ...
  mail:
    host: smtp.gmail.com
    port: 587
    username: helpringproject@gmail.com
    password: 
    properties:
      mail.smtp.auth: true
      mail.smtp.ssl.enable: true

mail.smtp.ssl.enable: true
gmail의 tsl port 주소 587을 입력해놓고 tsl이 아닌 ssl로 작성한 것!!!!!!
starttls는 JavaMail에 TLS모드를 시작하라고 명시적으로 요청한다. 따라서 starttls 설정을 적용해주어야 한다.

  mail:
    host: smtp.gmail.com
    port: 587
    username: helpringproject@gmail.com
    password: 
    properties:
      mail.smtp.auth: true
      mail.smtp.starttls.enable: true

mail.smtp.starttls.enable: true
위와 같이 수정해주었다.

성공~!

0개의 댓글