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