diff --git a/main-server/src/main/java/com/sickgyun/server/mail/MailService.java b/main-server/src/main/java/com/sickgyun/server/mail/MailService.java index 6fe921a..7acd6a7 100644 --- a/main-server/src/main/java/com/sickgyun/server/mail/MailService.java +++ b/main-server/src/main/java/com/sickgyun/server/mail/MailService.java @@ -28,11 +28,9 @@ public void sendMail(CoffeeChat coffeeChat) { MimeMessage message = mailSender.createMimeMessage(); try { - message.addRecipients(TO, coffeeChat.getToUser().getEmail()); - message.setSubject("안녕하세요. 식견입니다."); + setRecipientsAndFrom(coffeeChat, message); + message.setSubject(setSubjectWithCoffeeChat(coffeeChat)); message.setText(setContext(coffeeChat), "utf-8", "html"); - - message.setFrom(coffeeChat.getFromUser().getEmail()); } catch (MessagingException e) { throw new EmailNotExistException(); } @@ -40,6 +38,28 @@ public void sendMail(CoffeeChat coffeeChat) { mailSender.send(message); } + private void setRecipientsAndFrom(CoffeeChat coffeeChat, MimeMessage message) throws MessagingException { + if (coffeeChat.getState().equals(State.PENDING)) { + message.addRecipients(TO, coffeeChat.getToUser().getEmail()); + message.setFrom(coffeeChat.getFromUser().getEmail()); + } else { + message.addRecipients(TO, coffeeChat.getFromUser().getEmail()); + message.setFrom(coffeeChat.getToUser().getEmail()); + } + } + + private String setSubjectWithCoffeeChat(CoffeeChat coffeeChat) { + String fromUserName = coffeeChat.getFromUser().getName(); + String toUserName = coffeeChat.getToUser().getName(); + + if (coffeeChat.getState().equals(State.ACCEPT)) { + return toUserName + "님께서 " + fromUserName + "님의 커피챗 요청을 수락하셨어요."; + } else if (coffeeChat.getState().equals(State.REJECT)) { + return toUserName + "님께서 " + fromUserName + "님의 커피챗 요청을 거절하셨어요...ㅠ"; + } + return fromUserName + "님으로부터 커피챗 요청이 왔어요."; + } + private String setContext(CoffeeChat coffeeChat) { Context context = new Context(); context.setVariable("fromuser", coffeeChat.getFromUser().getName()); diff --git a/main-server/src/main/resources/templates/accept-mail.html b/main-server/src/main/resources/templates/accept-mail.html index f44d448..58e077b 100644 --- a/main-server/src/main/resources/templates/accept-mail.html +++ b/main-server/src/main/resources/templates/accept-mail.html @@ -5,30 +5,33 @@