|
| 1 | +package com.cona.KUsukKusuk.email; |
| 2 | + |
| 3 | +import java.util.Properties; |
| 4 | +import org.springframework.beans.factory.annotation.Value; |
| 5 | +import org.springframework.context.annotation.Bean; |
| 6 | +import org.springframework.context.annotation.Configuration; |
| 7 | +import org.springframework.mail.javamail.JavaMailSender; |
| 8 | +import org.springframework.mail.javamail.JavaMailSenderImpl; |
| 9 | +@Configuration |
| 10 | +public class EmailConfig { |
| 11 | + @Value("${spring.mail.host}") |
| 12 | + private String host; |
| 13 | + |
| 14 | + @Value("${spring.mail.port}") |
| 15 | + private int port; |
| 16 | + |
| 17 | + @Value("${spring.mail.username}") |
| 18 | + private String username; |
| 19 | + |
| 20 | + @Value("${spring.mail.password}") |
| 21 | + private String password; |
| 22 | + |
| 23 | + @Value("${spring.mail.properties.mail.smtp.auth}") |
| 24 | + private boolean auth; |
| 25 | + |
| 26 | + @Value("${spring.mail.properties.mail.smtp.starttls.enable}") |
| 27 | + private boolean starttlsEnable; |
| 28 | + |
| 29 | + @Value("${spring.mail.properties.mail.smtp.starttls.required}") |
| 30 | + private boolean starttlsRequired; |
| 31 | + |
| 32 | + @Value("${spring.mail.properties.mail.smtp.connectiontimeout}") |
| 33 | + private int connectionTimeout; |
| 34 | + |
| 35 | + @Value("${spring.mail.properties.mail.smtp.timeout}") |
| 36 | + private int timeout; |
| 37 | + |
| 38 | + @Value("${spring.mail.properties.mail.smtp.writetimeout}") |
| 39 | + private int writeTimeout; |
| 40 | + |
| 41 | + @Bean |
| 42 | + public JavaMailSender javaMailSender() { |
| 43 | + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); |
| 44 | + mailSender.setHost(host); |
| 45 | + mailSender.setPort(port); |
| 46 | + mailSender.setUsername(username); |
| 47 | + mailSender.setPassword(password); |
| 48 | + mailSender.setDefaultEncoding("UTF-8"); |
| 49 | + mailSender.setJavaMailProperties(getMailProperties()); |
| 50 | + |
| 51 | + return mailSender; |
| 52 | + } |
| 53 | + |
| 54 | + private Properties getMailProperties() { |
| 55 | + Properties properties = new Properties(); |
| 56 | + properties.put("mail.smtp.auth", auth); |
| 57 | + properties.put("mail.smtp.starttls.enable", starttlsEnable); |
| 58 | + properties.put("mail.smtp.starttls.required", starttlsRequired); |
| 59 | + properties.put("mail.smtp.connectiontimeout", connectionTimeout); |
| 60 | + properties.put("mail.smtp.timeout", timeout); |
| 61 | + properties.put("mail.smtp.writetimeout", writeTimeout); |
| 62 | + |
| 63 | + return properties; |
| 64 | + } |
| 65 | +} |
0 commit comments