Skip to content

Commit

Permalink
[feat] : Email Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBean99 committed Sep 2, 2023
1 parent 8837cbe commit 6a9ca9e
Show file tree
Hide file tree
Showing 34 changed files with 701 additions and 111 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
branches:
- master
- develop
pull_request:
branches:
- develop
- release
jobs:
deploy-production:
name: Deploy(Production)
Expand Down Expand Up @@ -43,14 +47,10 @@ jobs:
script_start: |
cd ~/econo-recruit/server # 원하는 경로로 변경하세요.
script: |
sh docker-install.sh
echo "start docker-compose up: econovation-server"
sudo docker-compose -v
cat .env
sudo docker-compose -f docker-compose.yml pull
sudo docker-compose -f docker-compose.yml --env-file .env up --build -d
echo "prune images"
sudo docker system prune --all -f
echo "start deploy: restart server econovation-server"
sudo docker-compose
cat .env
sudo sh deploy.sh
- name: Notify on success
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ out/

### VS Code ###
.vscode/
.env
server/.env
.env.*

*.xlsx
Expand Down
Binary file modified .gradle/7.6.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.6.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/checksums/checksums.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified server/.gradle/7.6.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified server/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified server/.gradle/file-system.probe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.econovation.recruit.api.applicant.handler;

import com.econovation.recruit.api.card.usecase.BoardRegisterUseCase;
import com.econovation.recruitdomain.domains.applicant.event.ApplicantRegisterEvent;
import com.econovation.recruitdomain.domains.card.adaptor.CardAdaptor;
import com.econovation.recruitdomain.domains.card.domain.Card;
import com.econovation.recruitinfrastructure.mail.EmailSenderService;
import com.econovation.recruitinfrastructure.mail.GoogleMailProperties;
import com.econovation.recruitinfrastructure.slack.SlackMessageProvider;
import com.econovation.recruitinfrastructure.slack.config.SlackProperties;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
@Slf4j
public class ApplicantRegisterEventConfirmEmailHandler {
private final GoogleMailProperties googleMailProperties;
private final EmailSenderService emailSenderService;
@Async
@TransactionalEventListener(
classes = ApplicantRegisterEvent.class,
phase = TransactionPhase.AFTER_COMMIT)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void handle(ApplicantRegisterEvent applicantRegistEvent) {
log.info("%s님의 지원서가 접수되었습니다.", applicantRegistEvent.getUserName());
try{
MimeMessage mimeMessage = emailSenderService.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, "utf-8");
helper.setFrom(googleMailProperties.getUsername());
helper.setTo(applicantRegistEvent.getEmail());
helper.setSubject("[Econovation] 에코노베이션 지원서 접수 확인 메일");
helper.setText(generateConfirmRegisterEmailBody(applicantRegistEvent.getEmail(), applicantRegistEvent.getUserName()), true);
emailSenderService.sendEmail(mimeMessage);
} catch (MessagingException e) {
log.error("메일 content 생성에 실패하였습니다.. {}", e.getMessage());
}
}
//
// MimeMessage mimeMessage = generateConfirmRegisterEmail(
// applicantRegistEvent.getEmail(),
// applicantRegistEvent.getUserName());
// emailSenderService.sendEmail(mimeMessage);

/* private SimpleMailMessage generateConfirmRegisterEmail(
String email, String userName) {
SimpleMailMessage message = emailSenderService.
MimeMessageHelper helper = new MimeMessageHelper(message, "utf-8");
try {
helper.setFrom(googleMailProperties.getUsername());
helper.setTo(email);
helper.setSubject("[Econovation] 에코노베이션 지원서 접수 확인 메일");
helper.setText(generateConfirmRegisterEmailBody(email, userName), true);
} catch (MessagingException e) {
log.error("메일 content 생성에 실패하였습니다.. {}", e.getMessage());
}
return message;
}*/

private String generateConfirmRegisterEmailBody(String email, String userName) {
return String.format(
"안녕하세요 %s님,\n\n"
+ "저희 에코노베이션에 지원해주셔서 진심으로 감사드립니다.\n\n"
+ "귀하의 지원이 성공적으로 접수되었음을 알려드립니다. "
+ "저희 팀은 지원서를 신중히 검토한 후, 빠른 시일 내에 연락드리겠습니다.\n\n"
+ "혹시 궁금한 사항이 있으시면 언제든지 저희에게 연락주시기 바랍니다.\n\n"
+ "다시 한번 감사의 말씀을 드리며, 좋은 결과가 있기를 바랍니다.\n\n"
+ "감사합니다,\n"
+ "- 에코노베이션 Recruit팀",
userName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.econovation.recruitdomain.domains.applicant.domain.Question;
import com.econovation.recruitdomain.domains.applicant.dto.BlockRequestDto;
import com.econovation.recruitdomain.domains.applicant.event.ApplicantRegisterEvent;
import com.econovation.recruitdomain.domains.applicant.exception.AnswerEmptyFieldException;
import com.econovation.recruitdomain.domains.applicant.exception.ApplicantDuplicateSubmitException;
import com.econovation.recruitdomain.domains.applicant.exception.QuestionNotFoundException;
import java.util.List;
Expand Down Expand Up @@ -80,17 +81,21 @@ public UUID execute(List<BlockRequestDto> blocks) {
.filter(answer -> answer.getQuestion().getName().equals("field"))
.findFirst()
.map(Answer::getAnswer)
.orElseThrow(() -> new RuntimeException("희망 분야를 찾을 수 없습니다."));
.orElseThrow(() -> AnswerEmptyFieldException.EXCEPTION);

String name =
results.stream()
.filter(answer -> answer.getQuestion().getName().equals("name"))
.findFirst()
.map(Answer::getAnswer)
.orElseThrow(() -> new RuntimeException("이름을 찾을 수 없습니다."));

.orElseThrow(() -> AnswerEmptyFieldException.EXCEPTION);
String email = results.stream()
.filter(answer -> answer.getQuestion().getName().equals("email"))
.findFirst()
.map(Answer::getAnswer)
.orElseThrow(() -> AnswerEmptyFieldException.EXCEPTION);
ApplicantRegisterEvent applicantRegisterEvent =
ApplicantRegisterEvent.of(applicantId.toString(), name, hopeField);
ApplicantRegisterEvent.of(applicantId.toString(), name, hopeField,email);
Events.raise(applicantRegisterEvent);
return applicantId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void checkPassword(String password, String encodePassword) {
@Override
@Transactional
public void signUp(SignUpRequestDto signUpRequestDto) {
if (interviewerLoadPort.loadOptionalInterviewerByEmail(signUpRequestDto.getEmail()) == null)
if (interviewerLoadPort.loadOptionalInterviewerByEmail(signUpRequestDto.getEmail()) != null)
throw InterviewerAlreadySubmitException.EXCEPTION;
String encededPassword = passwordEncoder.encode(signUpRequestDto.getPassword());
Interviewer interviewer =
Expand Down
3 changes: 2 additions & 1 deletion server/Recruit-Domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ jar { enabled = true }
dependencies {
api 'org.springframework.boot:spring-boot-starter-data-jpa'
api 'mysql:mysql-connector-java'
runtimeOnly 'com.h2database:h2'
// test h2
testRuntimeOnly 'com.h2database:h2'
implementation project(':Recruit-Common')
implementation project(':Recruit-Infrastructure')
//flyway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class ApplicantRegisterEvent extends DomainEvent {
private final String applicantId;
private final String hopeField;
private final String userName;
private final String email;

public static ApplicantRegisterEvent of(String applicantId, String userName, String hopeField) {
public static ApplicantRegisterEvent of(String applicantId, String userName, String hopeField, String email){
return ApplicantRegisterEvent.builder()
.applicantId(applicantId)
.hopeField(hopeField)
.userName(userName)
.email(email)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.econovation.recruitdomain.domains.applicant.exception;

import com.econovation.recruitcommon.exception.RecruitCodeException;
import com.econovation.recruitdomain.domains.applicant.domain.Answer;

public class AnswerEmptyFieldException extends RecruitCodeException {
public static RecruitCodeException EXCEPTION = new AnswerEmptyFieldException();
private AnswerEmptyFieldException() {super(AnswerErrorCode.ANSWER_EMPTY_FIELD);}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.econovation.recruitdomain.domains.applicant.exception;

import com.econovation.recruitcommon.annotation.ExplainError;
import com.econovation.recruitcommon.exception.BaseErrorCode;
import com.econovation.recruitcommon.exception.ErrorReason;
import java.lang.reflect.Field;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;

import static com.econovation.recruitcommon.consts.RecruitStatic.BAD_REQUEST;
import static com.econovation.recruitcommon.consts.RecruitStatic.NOT_FOUND;

@Getter
@AllArgsConstructor
public enum AnswerErrorCode implements BaseErrorCode {
ANSWER_NOT_FOUND(NOT_FOUND, "ANSWER_NOT_FOUND", "지원자를 찾을 수 없습니다."),
ANSWER_EMPTY_FIELD(BAD_REQUEST, "ANSWER_400_0", "필수 입력값이 없습니다."),
ANSWER_DUPLICATE_SUBMIT(BAD_REQUEST, "ANSWER_400_1", "이미 지원한 지원자입니다."),
;

private Integer status;
private String code;
private String reason;

@Override
public ErrorReason getErrorReason() {
return ErrorReason.builder().reason(reason).code(code).status(status).build();
}

@Override
public String getExplainError() throws NoSuchFieldException {
Field field = this.getClass().getField(this.name());
ExplainError annotation = field.getAnnotation(ExplainError.class);
return Objects.nonNull(annotation) ? annotation.value() : this.getReason();
}
}
7 changes: 6 additions & 1 deletion server/Recruit-Infrastructure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ dependencies {
//for email
api 'org.springframework.boot:spring-boot-starter-thymeleaf'
api 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'

api 'com.sun.mail:javax.mail:1.6.2'
// amazon ses
api 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
api group: 'software.amazon.awssdk', name: 'ses', version: "2.19.29"
// api project(':Recruit-Domain')

testImplementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testImplementation "org.springframework.cloud:spring-cloud-starter-contract-stub-runner:3.1.5"
testImplementation "org.springframework.cloud:spring-cloud-contract-wiremock:3.1.5"

// pdf
api 'org.xhtmlrenderer:flying-saucer-pdf:9.1.20'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.econovation.recruitinfrastructure;

import com.econovation.recruitinfrastructure.mail.GoogleMailProperties;
import com.econovation.recruitinfrastructure.slack.config.SlackProperties;
import com.econovation.recruitinfrastructure.slack.config.SlackTFProperties;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties({SlackProperties.class, SlackTFProperties.class})
@EnableConfigurationProperties({SlackProperties.class, SlackTFProperties.class, GoogleMailProperties.class})
@Configuration
public class ConfigurationInfrastructurePropertiesConfig {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.econovation.recruitinfrastructure.mail;

import java.util.Properties;
import javax.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class EmailSenderService {
@Autowired private JavaMailSender javaMailSender;
@Autowired
public EmailSenderService(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
@Async
public void sendEmail(SimpleMailMessage email) {
javaMailSender.send(email);
}
@Async
public void sendEmail(MimeMessage email) {
javaMailSender.send(email);
}

public MimeMessage createMimeMessage() {
return javaMailSender.createMimeMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.econovation.recruitinfrastructure.mail;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;

@Getter
@AllArgsConstructor
@ConstructorBinding
@ConfigurationProperties(prefix = "spring.mail")
public class GoogleMailProperties {
private String host;
private Integer port;
private String username;
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.econovation.recruitinfrastructure.mail;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
@RequiredArgsConstructor
public class MailConfig {
private final GoogleMailProperties mailProperties;

@Bean
public JavaMailSenderImpl mailSender() {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setProtocol("smtp");
javaMailSender.setHost(mailProperties.getHost());
javaMailSender.setPort(mailProperties.getPort());
javaMailSender.setUsername(mailProperties.getUsername());
javaMailSender.setPassword(mailProperties.getPassword());
return javaMailSender;
}
}
Loading

0 comments on commit 6a9ca9e

Please sign in to comment.