Skip to content

Commit

Permalink
refactor: 메일 발송 형식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
mangowhoiscloud committed Nov 6, 2024
1 parent 2254d58 commit 423e01a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package aimo.backend.domains.member.dto.request;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;

public record SendTemporaryPasswordRequest(
@Email(message = "이메일 형식이 아닙니다.")
String email) {
@NotNull(message = "nickname이 빈 문자열입니다.")
String nickname,
@Email(message = "email 형식이 아닙니다.")
String email
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.UUID;


import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
Expand All @@ -12,6 +12,7 @@

import aimo.backend.domains.member.dto.request.SendTemporaryPasswordRequest;
import aimo.backend.domains.member.dto.response.SendTemporaryPasswordResponse;
import aimo.backend.domains.member.entity.Member;
import aimo.backend.infrastructure.smtp.model.Notice;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
Expand All @@ -28,19 +29,19 @@ public class MailService {
private final SpringTemplateEngine templateEngine;

public SendTemporaryPasswordResponse createMail(SendTemporaryPasswordRequest sendTemporaryPasswordRequest) {

return new SendTemporaryPasswordResponse(
sendTemporaryPasswordRequest.email(),
Notice.TITLE.getValue(),
Notice.INTRODUCE.getValue() + Notice.TEMPORARY_PASSWORD.getValue() + createTempPassword() + Notice.END_MESSAGE.getValue() + Notice.FROM.getValue(),
Notice.INTRODUCE.getValue() + sendTemporaryPasswordRequest.nickname() +
Notice.TEMPORARY_PASSWORD.getValue() + createTempPassword() + Notice.END_MESSAGE.getValue() + Notice.FROM.getValue(),
Notice.SERVICE_ADDRESS.getValue());
}

private static String createTempPassword() {
return UUID.randomUUID().toString().substring(0, 8);
}

public void sendMail(SendTemporaryPasswordResponse sendTemporaryPasswordResponse) throws MessagingException {
public void sendHtmlMail(SendTemporaryPasswordResponse sendTemporaryPasswordResponse) throws MessagingException {
// 메일 전송 로직
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
Expand All @@ -60,4 +61,15 @@ public void sendMail(SendTemporaryPasswordResponse sendTemporaryPasswordResponse

javaMailSender.send(message);
}

public void sendMail(SendTemporaryPasswordResponse sendTemporaryPasswordResponse) {
// 메일 전송 로직
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(sendTemporaryPasswordResponse.to());
message.setSubject(sendTemporaryPasswordResponse.title());
message.setText(sendTemporaryPasswordResponse.content());
message.setFrom(sendTemporaryPasswordResponse.from());
message.setReplyTo(sendTemporaryPasswordResponse.from());
javaMailSender.send(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

@Getter
public enum Notice {
TITLE("Aimo 임시 비밀번호 발급 안내"),
TITLE("aimo 임시 비밀번호 발급 안내"),
INTRODUCE("임시 비밀번호 발급 안내입니다.\n"),
TEMPORARY_PASSWORD("님의 임시 비밀번호는 "),
END_MESSAGE("입니다.\n항상 Aimo를 이용해 주셔서 감사합니다.\n"),
FROM("\nAimo 개발자 mango 드림"),
END_MESSAGE("입니다.\n항상 aimo를 이용해 주셔서 감사합니다.\n"),
FROM("\naimo 담당자 드림"),
SERVICE_ADDRESS("[email protected]");

private String value;
Expand Down

0 comments on commit 423e01a

Please sign in to comment.