修复notify中mail模块的bug
This commit is contained in:
parent
baccb20c3c
commit
ca65b5e8fc
@ -4,12 +4,15 @@ import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author hxuanyu
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "notify.mail")
|
||||
@ConditionalOnProperty(prefix = "notify.mail", havingValue = "true")
|
||||
public class MailProperties {
|
||||
private static final Charset DEFAULT_CHARSET;
|
||||
private String host;
|
||||
@ -20,12 +23,25 @@ public class MailProperties {
|
||||
private Charset defaultEncoding;
|
||||
private Map<String, String> properties;
|
||||
private String jndiName;
|
||||
private Integer interval = 10000;
|
||||
|
||||
public MailProperties() {
|
||||
this.defaultEncoding = DEFAULT_CHARSET;
|
||||
this.properties = new HashMap();
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Integer getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public void setInterval(Integer interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class MailServiceImpl implements MailService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MailServiceImpl.class);
|
||||
private static boolean isRunning = true;
|
||||
ExecutorService executor;
|
||||
|
||||
@Resource
|
||||
private JavaMailSender javaMailSender;
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ public class MailServiceImpl implements MailService {
|
||||
if (mail != null) {
|
||||
//可以设置延时 以及重复校验等等操作
|
||||
sendMailSync(mail);
|
||||
Thread.sleep(10000);
|
||||
Thread.sleep(mailProperties.getInterval());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -72,6 +72,10 @@ public class MailServiceImpl implements MailService {
|
||||
|
||||
|
||||
private void sendMailSync(Mail mail) {
|
||||
if (mailProperties == null){
|
||||
logger.error("未配置邮件信息,请在配置文件中添加配置信息后再发送邮件");
|
||||
return;
|
||||
}
|
||||
String from = mail.getFrom();
|
||||
if (from == null) {
|
||||
from = mailProperties.getUsername();
|
||||
@ -107,11 +111,6 @@ public class MailServiceImpl implements MailService {
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setJavaMailSender(JavaMailSender javaMailSender) {
|
||||
this.javaMailSender = javaMailSender;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setExecutor(@Qualifier("mailExecutorService") ExecutorService executor) {
|
||||
this.executor = executor;
|
||||
|
@ -35,6 +35,11 @@
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for notify.mail.properties.mail.debug."
|
||||
},
|
||||
{
|
||||
"name": "notify.mail.properties.mail.interval",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for notify.mail.properties.mail.debug."
|
||||
},
|
||||
{
|
||||
"name": "notify.mail.properties.stmp.socketFactory.class",
|
||||
"type": "java.lang.String",
|
||||
|
@ -3,12 +3,13 @@ notify:
|
||||
host: smtp.qq.com
|
||||
protocol: smtp
|
||||
default-encoding: UTF-8
|
||||
password: bjmtskwfjrvqdhgb
|
||||
username: 2202043370@qq.com
|
||||
password: your pwd
|
||||
username: your account
|
||||
port: 587
|
||||
properties:
|
||||
mail:
|
||||
debug: false
|
||||
stmp:
|
||||
socketFactory:
|
||||
class: javax.net.ssl.SSLSocketFactory
|
||||
class: javax.net.ssl.SSLSocketFactory
|
||||
interval: 5000
|
Loading…
x
Reference in New Issue
Block a user