Skip to content

Commit

Permalink
feat : Java Mail Sender Config 세팅 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-ho committed Feb 11, 2024
1 parent 686f0d8 commit 7361094
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ spring:
logging:
level:
com.gdschongik.gdsc.domain.*.api.*: debug

gmail:
id: ${GMAIL_ID}
password: ${GMAIL_PASSWORD}

0 comments on commit 7361094

Please sign in to comment.