-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 메일 발송 비동기 처리 전환 #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/com/daramg/server/auth/application/AsyncMailSender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.daramg.server.auth.application; | ||
|
|
||
| import com.daramg.server.auth.domain.MailMessages; | ||
| import com.daramg.server.auth.util.MailContentBuilder; | ||
| import com.daramg.server.auth.util.MimeMessageGenerator; | ||
| import jakarta.mail.internet.MimeMessage; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.mail.javamail.JavaMailSender; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AsyncMailSender { | ||
|
|
||
| private final JavaMailSender javaMailSender; | ||
| private final MimeMessageGenerator mimeMessageGenerator; | ||
| private final MailContentBuilder mailContentBuilder; | ||
|
|
||
| @Async("mailTaskExecutor") | ||
| public void sendVerificationCode(String email, String verificationCode) { | ||
| try { | ||
| String htmlContent = mailContentBuilder.buildVerificationEmail(verificationCode); | ||
| MimeMessage mimeMessage = mimeMessageGenerator.generate( | ||
| email, | ||
| MailMessages.MAIL_VERIFICATION_SUBJECT, | ||
| htmlContent | ||
| ); | ||
| javaMailSender.send(mimeMessage); | ||
| } catch (Exception e) { | ||
| log.error("이메일 발송 실패 - email: {}, error: {}", email, e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/daramg/server/common/config/AsyncConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.daramg.server.common.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.scheduling.annotation.EnableAsync; | ||
| import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
|
||
| import java.util.concurrent.Executor; | ||
|
|
||
| @Configuration | ||
| @EnableAsync | ||
| public class AsyncConfig { | ||
|
|
||
| @Bean(name = "mailTaskExecutor") | ||
| public Executor mailTaskExecutor() { | ||
| ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
| executor.setCorePoolSize(2); | ||
| executor.setMaxPoolSize(5); | ||
| executor.setQueueCapacity(100); | ||
| executor.setThreadNamePrefix("mail-"); | ||
| executor.initialize(); | ||
| return executor; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이메일 발송 실패 시 사용자 이메일 주소가 평문으로 로깅되고 있습니다. 이메일 주소는 개인 식별 정보(PII)로 간주되며, PII를 평문으로 로깅하는 것은 보안 및 규정 준수 문제를 야기할 수 있습니다. 또한, 비동기 작업에서 예외 발생 시 원인 파악을 용이하게 하기 위해 전체 스택 트레이스를 로깅하는 것이 좋습니다.
e.getMessage()만 기록할 경우 상세 정보를 놓칠 수 있습니다. SLF4J의 로거는 마지막 인자로Throwable을 받으면 스택 트레이스를 자동으로 출력해줍니다. 이메일 주소는 마스킹 처리하고, 예외 발생 시 스택 트레이스를 함께 로깅하도록 수정해주세요.