33import dynamicquad .agilehub .global .exception .GeneralException ;
44import dynamicquad .agilehub .global .header .status .ErrorStatus ;
55import dynamicquad .agilehub .global .mail .model .EmailInfo ;
6- import dynamicquad .agilehub .issue .aspect .Retry ;
76import dynamicquad .agilehub .project .model .InviteEmailInfo ;
87import dynamicquad .agilehub .report .SummaryEmailInfo ;
98import jakarta .mail .MessagingException ;
109import jakarta .mail .internet .MimeMessage ;
11- import lombok .RequiredArgsConstructor ;
12-
1310import java .util .concurrent .CompletableFuture ;
14-
15- import org . springframework . mail . MailSendException ;
11+ import lombok . RequiredArgsConstructor ;
12+ import lombok . extern . slf4j . Slf4j ;
1613import org .springframework .mail .javamail .JavaMailSender ;
1714import org .springframework .mail .javamail .MimeMessageHelper ;
15+ import org .springframework .retry .annotation .Backoff ;
16+ import org .springframework .retry .annotation .Retryable ;
1817import org .springframework .scheduling .annotation .Async ;
1918import org .springframework .stereotype .Service ;
2019import org .springframework .util .StringUtils ;
2322
2423@ Service
2524@ RequiredArgsConstructor
25+ @ Slf4j
2626public class EmailService {
2727
2828 private final JavaMailSender mailSender ;
2929 private final SpringTemplateEngine templateEngine ;
3030
3131 @ Async ("emailExecutor" )
32- @ Retry (maxRetries = 3 , // 최대 3번 시도
33- retryFor = { MessagingException .class , MailSendException .class }, // 이메일 관련 예외만 재시도
34- delay = 1000 // 1초 대기 후 재시도
35- )
32+ @ Retryable (retryFor = {GeneralException .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 500 ))
3633 public CompletableFuture <Void > sendMail (EmailInfo emailInfo , String type ) {
3734 return CompletableFuture .runAsync (() -> {
3835 try {
3936 MimeMessage message = createMimeMessage (emailInfo , type );
4037 mailSender .send (message );
41- } catch (MessagingException me ) {
38+ } catch (Exception e ) {
39+ log .error ("Gmail SMTP 이메일 발송 실패: {}" , e .getMessage ());
4240 throw new GeneralException (ErrorStatus .EMAIL_NOT_SENT );
4341 }
4442 });
@@ -57,16 +55,17 @@ private MimeMessage createMimeMessage(EmailInfo emailInfo, String type) throws M
5755
5856 private String getEmailContent (EmailInfo emailInfo , String type ) {
5957 return StringUtils .hasText (type )
60- ? setContext (emailInfo , type )
61- : emailInfo .getMessage ();
58+ ? setContext (emailInfo , type )
59+ : emailInfo .getMessage ();
6260 }
6361
6462 private String setContext (EmailInfo emailInfo , String type ) {
6563 Context context = new Context ();
6664 if (type .equals ("invite" ) && emailInfo instanceof InviteEmailInfo inviteEmailMessage ) {
6765 context .setVariable ("projectName" , inviteEmailMessage .getProjectName ());
6866 context .setVariable ("inviteCode" , inviteEmailMessage .getInviteCode ());
69- } else if (type .equals ("reportSummary" ) && emailInfo instanceof SummaryEmailInfo summaryEmailMessage ) {
67+ }
68+ else if (type .equals ("reportSummary" ) && emailInfo instanceof SummaryEmailInfo summaryEmailMessage ) {
7069 context .setVariable ("projectName" , summaryEmailMessage .getProjectName ());
7170 context .setVariable ("report" , summaryEmailMessage .getReport ());
7271 }
0 commit comments