diff --git a/pom.xml b/pom.xml
index 997e25f..86fb78a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,9 +19,12 @@
1.2.0
3.2.0
- 4.3.9.RELEASE
- 4.3.10.Final
- 1.11.4.RELEASE
+ 4.3.9.RELEASE
+ 1.11.4.RELEASE
+ 4.2.3.RELEASE
+ 5.2.10.Final
+ 1.4.7
+ 1.9.13
@@ -51,17 +54,25 @@
org.springframework.data
spring-data-jpa
- ${spring-data-jpa}
+ ${spring.data.jpa.version}
org.springframework
spring-test
- ${spring-test-version}
+ ${spring.version}
test
+
+
+ org.springframework
+ spring-context-support
+ ${spring.version}
+
+
+
org.postgresql
@@ -72,7 +83,7 @@
org.codehaus.jackson
jackson-mapper-asl
- 1.9.13
+ ${jackson.mapper.version}
@@ -80,20 +91,28 @@
org.hibernate
hibernate-entitymanager
- 5.2.10.Final
+ ${hibernate.version}
org.hibernate
hibernate-core
- 5.2.10.Final
+ ${hibernate.version}
org.springframework.security
spring-security-crypto
- 4.2.3.RELEASE
+ ${spring.crypto.version}
+
+
+
+
+
+ javax.mail
+ mail
+ ${javax.mail.version}
diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java
new file mode 100644
index 0000000..72eed93
--- /dev/null
+++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java
@@ -0,0 +1,31 @@
+package com.loafle.overflow.module.email.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mail.MailException;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.stereotype.Service;
+
+/**
+ * Created by geek on 17. 6. 28.
+ */
+@Service
+public class EmailAuthService {
+
+ @Autowired
+ private JavaMailSender mailSender;
+
+ public void sendEmail(String to, String sub, String message) {
+
+ try {
+ SimpleMailMessage message1 = new SimpleMailMessage();
+ message1.setTo(to);
+ message1.setSubject(sub);
+ message1.setText(message);
+ message1.setFrom("geek@loafle.com");
+ mailSender.send(message1);
+ } catch (MailException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/com/loafle/overflow/spring/AppConfig.java b/src/main/java/com/loafle/overflow/spring/AppConfig.java
index 552e0bc..e454293 100644
--- a/src/main/java/com/loafle/overflow/spring/AppConfig.java
+++ b/src/main/java/com/loafle/overflow/spring/AppConfig.java
@@ -6,18 +6,23 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
/**
* Created by insanity on 17. 6. 13.
*/
@Configuration
@ComponentScan(basePackages = {"com.loafle.overflow"}, excludeFilters = @ComponentScan.Filter({Configuration.class}))
-@PropertySource({"classpath:database.properties"})
+@PropertySource({"classpath:database.properties","classpath:mail.properties"})
public class AppConfig {
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
- ppc.setLocation(new ClassPathResource("database.properties"));
+// ppc.setLocation(new ClassPathResource("database.properties"));
+ ppc.setLocations(new Resource[] {
+ new ClassPathResource("database.properties"),
+ new ClassPathResource("mail.properties")
+ });
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
diff --git a/src/main/java/com/loafle/overflow/spring/MailConfiguration.java b/src/main/java/com/loafle/overflow/spring/MailConfiguration.java
new file mode 100644
index 0000000..423ef5d
--- /dev/null
+++ b/src/main/java/com/loafle/overflow/spring/MailConfiguration.java
@@ -0,0 +1,63 @@
+package com.loafle.overflow.spring;
+
+import org.springframework.beans.factory.annotation.Configurable;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+
+import java.util.Properties;
+
+/**
+ * Created by geek on 17. 6. 28.
+ */
+@Configurable
+@ComponentScan(basePackages = "com.loafle.overflow")
+public class MailConfiguration {
+
+ @Value("${mail.host}")
+ private String host;
+ @Value("${mail.port}")
+ private int port;
+ @Value("${mail.username}")
+ private String username;
+ @Value("${mail.password}")
+ private String password;
+ @Value("${mail.protocol}")
+ private String protocol;
+ @Value("${mail.properties.mail.smtp.auth}")
+ private boolean smtpAuth;
+ @Value("${mail.properties.mail.smtp.starttls.enable}")
+ private boolean ttlEnable;
+ @Value("${mail.transport.protocol}")
+ private String transProtocol;
+ @Value("${mail.smtps.ssl.checkserveridentity}")
+ private boolean checkserver;
+ @Value("${mail.smtps.ssl.trust}")
+ private String sslTrust;
+
+ @Bean
+ public JavaMailSender getMailSender() {
+ JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
+
+ mailSender.setHost(this.host);
+ mailSender.setPort(this.port);
+ mailSender.setUsername(this.username);
+ mailSender.setPassword(this.password);
+ mailSender.setProtocol(this.protocol);
+
+ Properties javaMailProperties = new Properties();
+ javaMailProperties.put("mail.smtp.starttls.enable", this.ttlEnable);
+ javaMailProperties.put("mail.smtp.auth", this.smtpAuth);
+ javaMailProperties.put("mail.transport.protocol", this.transProtocol);
+ javaMailProperties.put("mail.debug", "true");
+ javaMailProperties.put("mail.smtps.ssl.checkserveridentity", this.checkserver);
+ javaMailProperties.put("mail.smtps.ssl.trust", this.sslTrust);
+
+ mailSender.setJavaMailProperties(javaMailProperties);
+ return mailSender;
+ }
+
+}
+
diff --git a/src/main/resources/mail.properties b/src/main/resources/mail.properties
new file mode 100644
index 0000000..99f696d
--- /dev/null
+++ b/src/main/resources/mail.properties
@@ -0,0 +1,14 @@
+# Naver SMTP
+mail.host=smtp.worksmobile.com
+mail.port=465
+mail.username=geek@loafle.com
+mail.password=@loafle@5795
+mail.protocol=smtps
+
+mail.properties.mail.smtp.auth=true
+mail.transport.protocol=smtp
+mail.properties.mail.smtp.starttls.enable=true
+mail.smtps.ssl.checkserveridentity=true
+mail.smtps.ssl.trust=*
+
+
diff --git a/src/test/java/com/loafle/overflow/module/email/service/EmailAuthServiceTest.java b/src/test/java/com/loafle/overflow/module/email/service/EmailAuthServiceTest.java
new file mode 100644
index 0000000..c4f4080
--- /dev/null
+++ b/src/test/java/com/loafle/overflow/module/email/service/EmailAuthServiceTest.java
@@ -0,0 +1,28 @@
+package com.loafle.overflow.module.email.service;
+
+import com.loafle.overflow.spring.AppConfig;
+import com.loafle.overflow.spring.JdbcConfiguration;
+import com.loafle.overflow.spring.MailConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by geek on 17. 6. 28.
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {AppConfig.class,MailConfiguration.class})
+public class EmailAuthServiceTest {
+
+ @Autowired
+ EmailAuthService emailAuthService;
+
+ @Test
+ public void TestMailSend() throws Exception {
+ this.emailAuthService.sendEmail("geek@loafle.com","Spring Email Test","Spring Email Test");
+ }
+}
\ No newline at end of file