From 73610945eb22640b26fdc1e36b5a6756c4fae0fc Mon Sep 17 00:00:00 2001 From: binary_ho Date: Mon, 12 Feb 2024 04:37:25 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Java=20Mail=20Sender=20Config=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/JavaMailSenderConfig.java | 41 +++++++++++++++++++ src/main/resources/application.yml | 4 ++ 2 files changed, 45 insertions(+) create mode 100644 src/main/java/com/gdschongik/gdsc/domain/integration/JavaMailSenderConfig.java diff --git a/src/main/java/com/gdschongik/gdsc/domain/integration/JavaMailSenderConfig.java b/src/main/java/com/gdschongik/gdsc/domain/integration/JavaMailSenderConfig.java new file mode 100644 index 000000000..62ec6d234 --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/integration/JavaMailSenderConfig.java @@ -0,0 +1,41 @@ +package com.gdschongik.gdsc.domain.integration; + +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 JavaMailSenderConfig { + + @Value("${gmail.id}") + private String id; + + @Value("${gmail.password}") + private String password; + + @Bean + public JavaMailSender javaMailSender() { + JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); + javaMailSender.setHost("smtp.gmail.com"); + javaMailSender.setPort(456); + javaMailSender.setUsername(id); + javaMailSender.setPassword(password); + javaMailSender.setJavaMailProperties(getMailProperties()); + javaMailSender.setDefaultEncoding("UTF-8"); + return javaMailSender; + } + + private Properties getMailProperties() { + Properties properties = new Properties(); + properties.put("mail.smtp.socketFactory.port", 456); + properties.put("mail.smtp.auth", true); + properties.put("mail.smtp.starttls.enable", true); + properties.put("mail.smtp.starttls.required", true); + properties.put("mail.smtp.socketFactory.fallback", false); + properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + return properties; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 41ff71fc6..6021618d2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,3 +13,7 @@ spring: logging: level: com.gdschongik.gdsc.domain.*.api.*: debug + +gmail: + id: ${GMAIL_ID} + password: ${GMAIL_PASSWORD}