From 052ff1ceffb768d5b5d8a988561c4c9e993ba694 Mon Sep 17 00:00:00 2001 From: Jaewon Lee <58386334+jaewonLeeKOR@users.noreply.github.com> Date: Mon, 23 Sep 2024 01:45:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#176=20=EC=9D=B8=EC=A6=9D=20=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EB=B0=9C=EC=86=A1=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=B9=84=EB=8F=99=EA=B8=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/server/capple/CappleApplication.java | 2 ++ .../capple/domain/mail/service/MailServiceImpl.java | 11 ++++++++--- .../server/capple/domain/mail/service/MailUtil.java | 4 +++- .../capple/domain/mail/service/MailUtilImpl.java | 13 ++++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/server/capple/CappleApplication.java b/src/main/java/com/server/capple/CappleApplication.java index bcd0e14b..a032fc21 100644 --- a/src/main/java/com/server/capple/CappleApplication.java +++ b/src/main/java/com/server/capple/CappleApplication.java @@ -7,6 +7,7 @@ import org.springframework.cache.annotation.EnableCaching; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import java.time.ZoneId; @@ -18,6 +19,7 @@ @EnableConfigurationProperties @EnableScheduling @EnableCaching +@EnableAsync public class CappleApplication { public static void main(String[] args) { diff --git a/src/main/java/com/server/capple/domain/mail/service/MailServiceImpl.java b/src/main/java/com/server/capple/domain/mail/service/MailServiceImpl.java index 08b36210..8ac8df0f 100644 --- a/src/main/java/com/server/capple/domain/mail/service/MailServiceImpl.java +++ b/src/main/java/com/server/capple/domain/mail/service/MailServiceImpl.java @@ -7,8 +7,10 @@ import com.server.capple.global.exception.RestApiException; import com.server.capple.global.exception.errorCode.MailErrorCode; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +@Slf4j @Service @RequiredArgsConstructor public class MailServiceImpl implements MailService { @@ -19,9 +21,12 @@ public class MailServiceImpl implements MailService { @Override public Boolean sendMailAddressCertificationMail(String email, Boolean isWhiteList) { - String certCode = mailUtil.sendMailAddressCertificationMail(email, isWhiteList); - String emailJwt = jwtService.createJwtFromEmail(email); - return mailRedisRepository.save(emailJwt, certCode); + mailUtil.sendMailAddressCertificationMail(email, isWhiteList).thenAccept(certCode -> { + String emailJwt = jwtService.createJwtFromEmail(email); + mailRedisRepository.save(emailJwt, certCode); + log.info("메일 발송 완료 : {}", email); + }); + return true; } @Override diff --git a/src/main/java/com/server/capple/domain/mail/service/MailUtil.java b/src/main/java/com/server/capple/domain/mail/service/MailUtil.java index 538c7fa2..efe6018d 100644 --- a/src/main/java/com/server/capple/domain/mail/service/MailUtil.java +++ b/src/main/java/com/server/capple/domain/mail/service/MailUtil.java @@ -1,10 +1,12 @@ package com.server.capple.domain.mail.service; +import java.util.concurrent.CompletableFuture; + public interface MailUtil { public static Boolean emailAddressFormVerification(String emailAddress) { String emailRegex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$"; return emailAddress.matches(emailRegex); } - String sendMailAddressCertificationMail(String receiver, Boolean isWhiteList); + CompletableFuture sendMailAddressCertificationMail(String receiver, Boolean isWhiteList); } diff --git a/src/main/java/com/server/capple/domain/mail/service/MailUtilImpl.java b/src/main/java/com/server/capple/domain/mail/service/MailUtilImpl.java index 2901e3c6..72037a52 100644 --- a/src/main/java/com/server/capple/domain/mail/service/MailUtilImpl.java +++ b/src/main/java/com/server/capple/domain/mail/service/MailUtilImpl.java @@ -5,13 +5,18 @@ import jakarta.mail.MessagingException; import jakarta.mail.internet.MimeMessage; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; +import java.util.concurrent.CompletableFuture; + +@Slf4j @Component @RequiredArgsConstructor public class MailUtilImpl implements MailUtil { @@ -20,10 +25,11 @@ public class MailUtilImpl implements MailUtil { @Value("${mail.white-list-cert-code}") private String whiteListCertCode; + @Async @Override - public String sendMailAddressCertificationMail(String receiver, Boolean isWhiteList) { + public CompletableFuture sendMailAddressCertificationMail(String receiver, Boolean isWhiteList) { String certCode = generateCertCode(); - if(isWhiteList) certCode = whiteListCertCode; + if (isWhiteList) certCode = whiteListCertCode; MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); @@ -31,8 +37,9 @@ public String sendMailAddressCertificationMail(String receiver, Boolean isWhiteL mimeMessageHelper.setSubject("[Capple] 회원가입 인증코드 안내"); mimeMessageHelper.setText(setCertMailContext(certCode), true); javaMailSender.send(mimeMessage); - return certCode; + return CompletableFuture.completedFuture(certCode); } catch (MessagingException e) { + log.error(MailErrorCode.MULTI_PART_CRAETION_FAILED.getMessage()); throw new RestApiException(MailErrorCode.MULTI_PART_CRAETION_FAILED); } }