diff --git a/bucketback-infrastructure/src/main/java/com/programmers/bucketback/mail/EmailSender.java b/bucketback-infrastructure/src/main/java/com/programmers/bucketback/mail/EmailSender.java deleted file mode 100644 index 659c005e8..000000000 --- a/bucketback-infrastructure/src/main/java/com/programmers/bucketback/mail/EmailSender.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.programmers.bucketback.mail; - -import java.util.UUID; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.stereotype.Component; - -import jakarta.mail.Message; -import jakarta.mail.MessagingException; -import jakarta.mail.internet.MimeMessage; -import lombok.RequiredArgsConstructor; - -@Component -@RequiredArgsConstructor -public class EmailSender { - - private final JavaMailSender javaMailSender; - - @Value("${spring.mail.username}") - private String fromEmail; - - public String send(final String email) { - final String code = createCode(); - final MimeMessage message; - try { - message = createMessage(email, code); - } catch (MessagingException e) { - throw new RuntimeException("이메일 인증코드 전송이 실패했습니다."); - } - javaMailSender.send(message); - - return code; - } - - private String createCode() { - return UUID.randomUUID() - .toString() - .replace("-", "") - .substring(0, 10); - } - - private MimeMessage createMessage( - final String toEmail, - final String code - ) throws MessagingException { - - final String subject = "Bucket-Back 회원가입 인증 코드"; - String text = ""; - text += "

안녕하세요.

"; - text += "

Bucket-Back 인증 코드는 다음과 같습니다.

"; - text += "

" + code + "

"; - text += "

감사합니다.

"; - - final MimeMessage message = javaMailSender.createMimeMessage(); - message.addRecipients(Message.RecipientType.TO, toEmail); - message.setSubject(subject); - message.setFrom(fromEmail); - message.setText(text, "utf-8", "html"); - - return message; - } -} diff --git a/bucketback-infrastructure/src/main/java/com/programmers/bucketback/mail/config/MailConfiguration.java b/bucketback-infrastructure/src/main/java/com/programmers/bucketback/mail/config/MailConfiguration.java deleted file mode 100644 index 9d67254da..000000000 --- a/bucketback-infrastructure/src/main/java/com/programmers/bucketback/mail/config/MailConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.programmers.bucketback.mail.config; - -import java.util.Properties; - -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; - -@Configuration -public class MailConfiguration { - - @Value("${spring.mail.username}") - private String username; - - @Value("${spring.mail.password}") - private String password; - - @Bean - public JavaMailSender javaMailSender() { - final JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); - mailSender.setHost("smtp.gmail.com"); - mailSender.setPort(587); - - mailSender.setUsername(username); - mailSender.setPassword(password); - - final 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; - } -}