Skip to content

Commit

Permalink
Feat: EmailConfig 추가 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kduoh99 committed Nov 2, 2024
1 parent a0afd59 commit e6239f1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/com/hackathon/momento/global/config/EmailConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.hackathon.momento.global.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 EmailConfig {

@Value("${spring.mail.host}")
private String host;

@Value("${spring.mail.port}")
private int port;

@Value("${spring.mail.username}")
private String username;

@Value("${spring.mail.password}")
private String password;

@Bean
public JavaMailSender javaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setPort(port);
mailSender.setHost(host);
mailSender.setUsername(username);
mailSender.setPassword(password);
mailSender.setDefaultEncoding("UTF-8");
mailSender.setJavaMailProperties(getMailProperties());

return mailSender;
}

private Properties getMailProperties() {
Properties properties = new Properties();
properties.put("mail.smtp.auth", true);
properties.put("mail.smtp.starttls.enable", true);
properties.put("mail.smtp.starttls.required", true);
properties.put("mail.smtp.connectiontimeout", 5000);
properties.put("mail.smtp.timeout", 5000);
properties.put("mail.smtp.writetimeout", 5000);

return properties;
}
}

6 changes: 6 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ spring:
port: ${REDIS_PORT}
host: ${REDIS_SERVER}

mail:
port: ${MAIL_PORT}
host: ${MAIL_SERVER}
username: ${MAIL_USERNAME}
password: ${MAIL_PASSWORD}

logging:
level:
org.hibernate.sql: debug
Expand Down

0 comments on commit e6239f1

Please sign in to comment.