Skip to content

Commit

Permalink
Merge pull request #141 from survey-mate/refactor/140
Browse files Browse the repository at this point in the history
refactor: mail 패키지 리팩토링
  • Loading branch information
JinhyeokFang authored Feb 16, 2024
2 parents 67cf984 + 3be52d5 commit a23086a
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 104 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@
import lombok.extern.slf4j.Slf4j;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import uk.jinhy.survey_mate_api.common.email.service.MailSender;
import uk.jinhy.survey_mate_api.common.email.service.dto.MailSenderDTO.SendMailDTO;
import uk.jinhy.survey_mate_api.common.response.Status;
import uk.jinhy.survey_mate_api.common.response.exception.GeneralException;

@Slf4j
@RequiredArgsConstructor
@Component
public class MailSenderImpl implements MailSender {

@Qualifier("mailSender")
private final JavaMailSender emailSender;

@Override
public void sendMail(SendMailDTO dto) {
MailjetRequest request;
Expand Down Expand Up @@ -52,10 +49,8 @@ public void sendMail(SendMailDTO dto) {
response = client.post(request);
} catch (MailjetException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
throw new GeneralException(Status.MAIL_SEND_FAIL);
}
System.out.println(response.getStatus());
System.out.println(response.getData());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@


import lombok.RequiredArgsConstructor;
import org.hibernate.validator.constraints.CodePointLength;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.jinhy.survey_mate_api.common.email.service.dto.MailSenderDTO;
import uk.jinhy.survey_mate_api.common.email.service.dto.MailServiceDTO.SendEmailDTO;
Expand All @@ -15,17 +13,13 @@ public class MailService {
private final MailSender mailSender;
private final TemplateRenderer templateRenderer;

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

public void sendEmail(SendEmailDTO sendEmailDTO) {
String content = templateRenderer.render(
sendEmailDTO.getTemplateFileName(),
sendEmailDTO.getTemplateContext()
);
MailSenderDTO.SendMailDTO sendMailDTO = MailSenderDTO.SendMailDTO.builder()
.content(content)
.from(sender)
.to(sendEmailDTO.getReceiver())
.subject(sendEmailDTO.getSubject())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class MailSenderDTO {
@AllArgsConstructor
public static class SendMailDTO {

public String from;
public String to;
public String content;
public String subject;
Expand Down
21 changes: 0 additions & 21 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@ spring:
hbm2ddl:
auto: update
default_batch_fetch_size: 1000
mail:
host: smtp.gmail.com
port: 465
username: [email protected]
password: ${MAIL_PASSWORD}
properties:
mail:
transport:
protocol: smtp
debug: true
mime:
charset: UTF-8
smtp:
auth: true
ssl:
enable: true
starttls:
enable: true
required: true
connection-timeout: 5000
timeout: 5000

cloud:
aws:
Expand Down

0 comments on commit a23086a

Please sign in to comment.