Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/main/java/dmu/dasom/api/domain/email/config/EmailConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dmu.dasom.api.domain.email.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class EmailConfig {

@Value("${spring.mail.username}")
private String username;
@Value("${spring.mail.password}")
private String password;

@Bean
public JavaMailSender javaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(587);
mailSender.setUsername(username);
mailSender.setPassword(password);

Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");

return mailSender;
}
}
28 changes: 17 additions & 11 deletions src/main/java/dmu/dasom/api/domain/email/service/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,36 @@
@Service
public class EmailService {

private JavaMailSender javaMailSender;
private TemplateEngine templateEngine;
private final TemplateEngine templateEngine;
private final JavaMailSender javaMailSender;

@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 emailContent;
String buttonUrl = "#";
String buttonUrl = "https://dmu-dasom.or.kr/recruit/result";
String buttonText;

switch (mailType) {
case DOCUMENT_RESULT -> {
subject = "동양미래대학교 컴퓨터소프트웨어공학과 전공 동아리 DASOM 서류 결과 안내";
emailContent = "먼저 다솜 34기에 많은 관심을 갖고 지원해 주셔서 감사드리며,<br>" +
"내부 서류 평가 결과 및 추후 일정에 관해 안내드리고자 이메일을 발송하게 되었습니다.<br>" +
"모집 폼 합/불합 결과는 아래 버튼 혹은 홈페이지를 통해 확인이 가능합니다.";
emailContent = "먼저 다솜 34기에 많은 관심을 두고 지원해 주셔서 감사드리며,<br>" +
"내부 서류 평가 결과 및 추후 일정에 관해 안내해드리고자 이메일을 발송하게 되었습니다.<br>" +
"서류 전형 결과는 아래 버튼 혹은 홈페이지를 통해 확인이 가능합니다.";
buttonText = "서류 결과 확인하기";
}
case FINAL_RESULT -> {
subject = "동양미래대학교 컴퓨터소프트웨어공학과 전공 동아리 DASOM 최종 합격 안내";
emailContent = "먼저 다솜 34기에 많은 관심을 갖고 지원해 주셔서 감사드리며,<br>" +
"최종 면접 결과 및 추후 일정에 관해 안내드리고자 이메일을 발송하게 되었습니다.<br>" +
"모집 폼 합/불합 결과는 아래 버튼 혹은 홈페이지를 통해 확인이 가능합니다.";
subject = "동양미래대학교 컴퓨터소프트웨어공학과 전공 동아리 DASOM 최종 면접 결과 안내";
emailContent = "먼저 다솜 34기에 많은 관심을 두고 지원해 주셔서 감사드리며,<br>" +
"최종 면접 결과 및 추후 일정에 관해 안내해드리고자 이메일을 발송하게 되었습니다.<br>" +
"최종 면접 결과는 아래 버튼 혹은 홈페이지를 통해 확인이 가능합니다.";
buttonText = "최종 결과 확인하기";
}
default -> throw new IllegalStateException("Unexpected value: " + mailType);
Expand All @@ -66,7 +69,10 @@ public void sendEmail(String to, String name, MailType mailType) throws Messagin
helper.setTo(to);
helper.setSubject(subject);
helper.setText(htmlBody, true);
helper.setFrom(from);
helper.setFrom((from != null && !from.isEmpty()) ? from : "[email protected]");

// Content-Type을 명시적으로 설정
message.setContent(htmlBody, "text/html; charset=utf-8");

javaMailSender.send(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public ResponseEntity<Void> modifyRecruitSchedule(@Valid @RequestBody final Recr
public ResponseEntity<Void> sendEmailsToApplicants(
@RequestParam
@Parameter(description = "메일 발송 타입", examples = {
@ExampleObject(name = "서류 합격 메일", value = "DOCUMENT_PASS"),
@ExampleObject(name = "서류 합격 메일", value = "DOCUMENT_RESULT"),
@ExampleObject(name = "최종 결과 메일", value = "FINAL_RESULT")
}) MailType mailType
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,139 +3,119 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<meta name="supported-color-schemes" content="light dark">
<title>이메일 안내</title>
<link rel="stylesheet" as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.css" />
<style>
body {
</head>
<body style="
background-color: #17171B;
color: white;
color: white !important;
font-family: 'Pretendard', sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.email-container {
margin: 0;">
<div style="
width: 740px;
height: 680px;
background: #17171B;
padding: 30px;
position: relative;
}

.logo {
position: relative;">
<div style="
display: flex;
justify-content: center;
position: relative;
margin-bottom: 20px;
}

.logo img {
width: 21px;
height: 24px;
border-radius: 3px;
}

.divider {
margin-bottom: 20px;">
<div style="
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
}

.divider .line {
align-items: center;">
<div style="
flex: 1;
border-top: 1px solid #00B493;
margin: 0 10px;">

</div>
<img src="https://dmu-dasom.or.kr/static/media/dasomLogo.c82d220d8093c3cb8d7fc0b148cafcd1.svg" alt="로고" style="
width: 21px;
height: 24px;
border-radius: 3px;">
<div style="
flex: 1;
border-top: 1px solid #00B493;
margin: 0 10px;
}
margin: 0 10px;">
</div>
</div>
</div>

.title {
<div style="
font-size: 48px;
font-weight: 900;
color: #00B493;
margin-bottom: 30px;
}

.greeting {
margin-bottom: 30px;">
DASOM
</div>
<div style="
font-size: 20px;
font-weight: 600;
margin-bottom: 40px;
}
margin-bottom: 5px;
color: white !important;"
th:text="${name} + '님 안녕하세요.'">
</div>
<div style="
font-size: 20px;
font-weight: 600;
margin-bottom: 5px;
color: white !important;">
컴퓨터공학부 전공동아리 다솜입니다.
</div>

.content {
<div style="
font-size: 16px;
font-weight: 400;
line-height: 2.5;
text-align: right;
margin-bottom: 40px;
}

.contact {
font-size: 16px;
font-weight: 400;
line-height: 1.5;
}
color: white !important;"
th:utext="${emailContent}">
</div>

.button-container {
display: flex;
<div style="display: flex;
justify-content: flex-end;
margin-bottom: 40px;
}

.button {
margin-bottom: 40px;">
<a th:href="${buttonUrl}"
style="
background: #00B493;
color: white;
color: white !important;
font-size: 16px;
font-weight: 400;
padding: 10px 20px;
border-radius: 5px;
display: flex;
align-items: center;
text-decoration: none;
}

.button:hover {
background: #00987A;
}

.button .arrow {
text-decoration: none;">
<span th:text="${buttonText}">
</span>
<span style="
border: solid white;
border-width: 0 2px 2px 0;
display: inline-block;
padding: 5px;
transform: rotate(-45deg);
margin-left: 10px;
}
</style>
</head>
<body>
<div class="email-container">
<div class="logo">
<div class="divider">
<div class="line"></div>
<img src="logo.png" alt="로고">
<div class="line"></div>
</div>
</div>

<div class="title">DASOM</div>
<div class="greeting" th:text="${name} + '님 안녕하세요.'"></div>
<div>컴퓨터공학부 전공동아리 다솜입니다.</div>

<div class="content" th:utext="${emailContent}"></div>

<div class="button-container">
<a th:href="${buttonUrl}" class="button">
<span th:text="${buttonText}"></span> <span class="arrow"></span>
margin-left: 10px;">
</span>
</a>
</div>

<div class="contact">
<div style="font-size: 16px;
font-weight: 400;
line-height: 1.5;
color: white !important;">
또한, 문의 사항은 본 메일에 회신 또는 아래 번호로 편하게 연락 부탁드립니다.<br>
010-6361-3481
</div>
</div>
</body>
</html>
</html>