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