email bean error modify
This commit is contained in:
parent
cf32ecc88e
commit
813857b021
|
@ -1,6 +1,7 @@
|
||||||
package com.loafle.overflow.module.email.service;
|
package com.loafle.overflow.module.email.service;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.mail.MailException;
|
import org.springframework.mail.MailException;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
@ -12,7 +13,7 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class EmailAuthService {
|
public class EmailAuthService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired()
|
||||||
private JavaMailSender mailSender;
|
private JavaMailSender mailSender;
|
||||||
|
|
||||||
public void sendEmail(String to, String sub, String message) {
|
public void sendEmail(String to, String sub, String message) {
|
||||||
|
@ -23,6 +24,7 @@ public class EmailAuthService {
|
||||||
message1.setSubject(sub);
|
message1.setSubject(sub);
|
||||||
message1.setText(message);
|
message1.setText(message);
|
||||||
message1.setFrom("geek@loafle.com");
|
message1.setFrom("geek@loafle.com");
|
||||||
|
|
||||||
mailSender.send(message1);
|
mailSender.send(message1);
|
||||||
} catch (MailException e) {
|
} catch (MailException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package com.loafle.overflow.spring;
|
package com.loafle.overflow.spring;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Configurable;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -12,8 +11,9 @@ import java.util.Properties;
|
||||||
/**
|
/**
|
||||||
* Created by geek on 17. 6. 28.
|
* Created by geek on 17. 6. 28.
|
||||||
*/
|
*/
|
||||||
@Configurable
|
@Configuration
|
||||||
@ComponentScan(basePackages = "com.loafle.overflow")
|
@ComponentScan(basePackages = "com.loafle.overflow")
|
||||||
|
//@ComponentScan(basePackages = "com.loafle.overflow", includeFilters = @ComponentScan.Filter(EmailAuth.class))
|
||||||
public class MailConfiguration {
|
public class MailConfiguration {
|
||||||
|
|
||||||
@Value("${mail.host}")
|
@Value("${mail.host}")
|
||||||
|
@ -26,6 +26,7 @@ public class MailConfiguration {
|
||||||
private String password;
|
private String password;
|
||||||
@Value("${mail.protocol}")
|
@Value("${mail.protocol}")
|
||||||
private String protocol;
|
private String protocol;
|
||||||
|
|
||||||
@Value("${mail.properties.mail.smtp.auth}")
|
@Value("${mail.properties.mail.smtp.auth}")
|
||||||
private boolean smtpAuth;
|
private boolean smtpAuth;
|
||||||
@Value("${mail.properties.mail.smtp.starttls.enable}")
|
@Value("${mail.properties.mail.smtp.starttls.enable}")
|
||||||
|
@ -38,7 +39,7 @@ public class MailConfiguration {
|
||||||
private String sslTrust;
|
private String sslTrust;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JavaMailSender getMailSender() {
|
public JavaMailSenderImpl mailSender() {
|
||||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||||
|
|
||||||
mailSender.setHost(this.host);
|
mailSender.setHost(this.host);
|
||||||
|
@ -47,6 +48,13 @@ public class MailConfiguration {
|
||||||
mailSender.setPassword(this.password);
|
mailSender.setPassword(this.password);
|
||||||
mailSender.setProtocol(this.protocol);
|
mailSender.setProtocol(this.protocol);
|
||||||
|
|
||||||
|
mailSender.setJavaMailProperties(getJavaMailProperties());
|
||||||
|
|
||||||
|
return mailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Properties getJavaMailProperties() {
|
||||||
Properties javaMailProperties = new Properties();
|
Properties javaMailProperties = new Properties();
|
||||||
javaMailProperties.put("mail.smtp.starttls.enable", this.ttlEnable);
|
javaMailProperties.put("mail.smtp.starttls.enable", this.ttlEnable);
|
||||||
javaMailProperties.put("mail.smtp.auth", this.smtpAuth);
|
javaMailProperties.put("mail.smtp.auth", this.smtpAuth);
|
||||||
|
@ -55,8 +63,7 @@ public class MailConfiguration {
|
||||||
javaMailProperties.put("mail.smtps.ssl.checkserveridentity", this.checkserver);
|
javaMailProperties.put("mail.smtps.ssl.checkserveridentity", this.checkserver);
|
||||||
javaMailProperties.put("mail.smtps.ssl.trust", this.sslTrust);
|
javaMailProperties.put("mail.smtps.ssl.trust", this.sslTrust);
|
||||||
|
|
||||||
mailSender.setJavaMailProperties(javaMailProperties);
|
return javaMailProperties;
|
||||||
return mailSender;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user