-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 메일 발송 기능 구현 #39
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58648bf
feat: google API 기능 추가
hodoon 31f5121
feat: google API 기능 추가
hodoon 40d8713
Merge branch 'feat/#14-1' into dev
hodoon ff4cfad
Merge remote-tracking branch 'origin/dev' into dev
hodoon 82c0d1a
Merge branch 'dev' of https://github.com/DASOM-GitHub/dasom-web-backe…
hodoon db28bfc
feat: 메일 발송 기능 구현
hodoon 52651c0
fix: 이메일 전송 관련 ErrorCode 수정
hodoon 8e3cfac
Merge branch 'dev' into feat/#38-1
hodoon 79d3fd5
feat: 서류 지원결과와 최종 합격 결과 API 나누기
hodoon 6bc4251
Merge remote-tracking branch 'origin/feat/#38-1' into feat/#38-1
hodoon 64e7268
fix: 서류 지원결과와 최종 합격 결과 API 하나의 메소드에서 지원되게 수정 MailType 열거형 추가
hodoon 272bd01
fix: ApplicantServiceImpl의 sendEmailsToApplicants 메소드 ApplicantStatus…
hodoon 526448a
test: ApplicantServiceImpl의 sendEmailsToApplicants 메소드 테스트 케이스 작성 및 E…
hodoon b0bf4ea
fix: EmailServiceTest에 들어가는 from의 value가 외부 환경변수를 인식하지 못하는 문제 발생 추후 테…
hodoon b834817
feat: EmailServiceTest 추가
hodoon 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
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
src/main/java/dmu/dasom/api/domain/applicant/repository/ApplicantRepository.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 |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| package dmu.dasom.api.domain.applicant.repository; | ||
|
|
||
| import dmu.dasom.api.domain.applicant.entity.Applicant; | ||
| import dmu.dasom.api.domain.applicant.enums.ApplicantStatus; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface ApplicantRepository extends JpaRepository<Applicant, Long> { | ||
|
|
||
| @Query("SELECT a FROM Applicant a ORDER BY a.id DESC") | ||
| Page<Applicant> findAllWithPageRequest(final Pageable pageable); | ||
|
|
||
| // 상태별 지원자 조회 | ||
| List<Applicant> findByStatus(ApplicantStatus status); | ||
| List<Applicant> findByStatusIn(List<ApplicantStatus> statuses); | ||
|
|
||
| Optional<Applicant> findByStudentNo(final String studentNo); | ||
|
|
||
| } |
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
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
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
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,6 @@ | ||
| package dmu.dasom.api.domain.email.enums; | ||
|
|
||
| public enum MailType { | ||
| DOCUMENT_RESULT, // 서류 합격 | ||
| FINAL_RESULT // 최종 합격 | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/main/java/dmu/dasom/api/domain/email/service/EmailService.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,62 @@ | ||
| package dmu.dasom.api.domain.email.service; | ||
|
|
||
| import dmu.dasom.api.domain.common.exception.CustomException; | ||
| import dmu.dasom.api.domain.common.exception.ErrorCode; | ||
| import dmu.dasom.api.domain.email.enums.MailType; | ||
| import jakarta.mail.MessagingException; | ||
| import jakarta.mail.internet.MimeMessage; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.mail.javamail.JavaMailSender; | ||
| import org.springframework.mail.javamail.MimeMessageHelper; | ||
| import org.springframework.stereotype.Service; | ||
| import org.thymeleaf.TemplateEngine; | ||
| import org.thymeleaf.context.Context; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class EmailService { | ||
|
|
||
| private JavaMailSender javaMailSender; | ||
| private TemplateEngine templateEngine; | ||
| @Value("${spring.mail.username}") | ||
| private String from; | ||
|
|
||
| public void sendEmail(String to, String name, MailType mailType) throws MessagingException { | ||
| if (mailType == null){ | ||
| throw new CustomException(ErrorCode.MAIL_TYPE_NOT_VALID); | ||
| } | ||
| // 메일 제목 및 템플릿 설정 | ||
| String subject; | ||
| String templateName = switch (mailType) { | ||
| case DOCUMENT_RESULT -> { | ||
| subject = "서류 합격 안내"; | ||
| yield "document-pass-template"; | ||
| } | ||
| case FINAL_RESULT -> { | ||
| subject = "최종 합격 안내"; | ||
| yield "final-pass-template"; | ||
| } | ||
| default -> throw new IllegalStateException("Unexpected value: " + mailType); | ||
| }; | ||
|
|
||
| // HTML 템플릿에 전달할 데이터 설정 | ||
| Context context = new Context(); | ||
| context.setVariable("name", name); // 지원자 이름 전달 | ||
|
|
||
| // HTML 템플릿 처리 | ||
| String htmlBody = templateEngine.process(templateName, context); | ||
|
|
||
| // 이메일 생성 및 전송 | ||
| MimeMessage message = javaMailSender.createMimeMessage(); | ||
| MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); | ||
|
|
||
| helper.setTo(to); | ||
| helper.setSubject(subject); | ||
| helper.setText(htmlBody, true); | ||
| helper.setFrom(from); | ||
|
|
||
| javaMailSender.send(message); | ||
| } | ||
|
|
||
| } |
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
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
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,79 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="ko"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>지원 결과 확인</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| background-color: #1a1a1a; | ||
| color: #ffffff; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| .container { | ||
| max-width: 600px; | ||
| margin: 0 auto; | ||
| padding: 20px; | ||
| background-color: #1a1a1a; | ||
| border-radius: 8px; | ||
| text-align: center; | ||
| } | ||
| .header { | ||
| font-size: 24px; | ||
| font-weight: bold; | ||
| color: #00B493; | ||
| margin-bottom: 20px; | ||
| } | ||
| .sub-header { | ||
| font-size: 16px; | ||
| background-color: #00B493; | ||
| padding: 10px; | ||
| border-radius: 5px; | ||
| margin-bottom: 20px; | ||
| } | ||
| .content { | ||
| font-size: 14px; | ||
| line-height: 1.8; | ||
| } | ||
| .content p { | ||
| margin-bottom: 10px; | ||
| } | ||
| .highlight { | ||
| color: #00B493; | ||
| } | ||
| .button { | ||
| display: inline-block; | ||
| background-color: #00B493; | ||
| color: #ffffff; | ||
| padding: 12px 24px; | ||
| border-radius: 5px; | ||
| text-decoration: none; | ||
| font-size: 16px; | ||
| } | ||
| .button:hover { | ||
| background-color: #00B493; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="container"> | ||
| <!-- Header Section --> | ||
| <div class="header">DASOM</div> | ||
|
|
||
| <!-- Sub-header Section --> | ||
| <div class="sub-header">컴퓨터소프트웨어공학과 전공동아리 다솜<br>34기 서류 합격자 조회</div> | ||
|
|
||
| <!-- Content Section --> | ||
| <div class="content"> | ||
| <p>안녕하세요, <span class="highlight" th:text="${name}"></span>님.</p> | ||
| <p>학번 마지막 <span class="highlight">4자리</span> + 전화번호 마지막 <span class="highlight">4자리</span>를 입력하여<br>지원 결과를 확인할 수 있습니다.</p> | ||
| <p>예시) <span class="highlight">08470542</span></p> | ||
|
|
||
| <!-- Button --> | ||
| <a href="https://example.com/result" class="button">결과 확인하기</a> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
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.
최종 결과 안내는 상태가
INTERVIEW_PASSED,INTERVIEW_FAILED인 지원자에게 발송하도록 수정해주세요