Commit e68f44d9 authored by Quxl's avatar Quxl

x

parent a1e2f276
...@@ -14,6 +14,7 @@ public class MailConfig { ...@@ -14,6 +14,7 @@ public class MailConfig {
private String from; private String from;
private String username; private String username;
private String password; private String password;
private boolean open;
public List<String> getTo() { public List<String> getTo() {
return to; return to;
} }
...@@ -50,4 +51,10 @@ public class MailConfig { ...@@ -50,4 +51,10 @@ public class MailConfig {
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
public boolean isOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
} }
...@@ -30,23 +30,25 @@ public class EmailService { ...@@ -30,23 +30,25 @@ public class EmailService {
} }
public void sendForsync(int tryCount, String subject, String content) { public void sendForsync(int tryCount, String subject, String content) {
try { if(config.isOpen()) {
String host = config.getHost(); try {
Integer port = config.getPort(); String host = config.getHost();
String username = config.getUsername(); Integer port = config.getPort();
String password = config.getPassword(); String username = config.getUsername();
String from = config.getFrom(); String password = config.getPassword();
List<String> to = config.getTo(); String from = config.getFrom();
MailUtil.sendBySmtp(host, port, true, username, password, from, subject, content, null, to.toArray(new String[to.size()])); List<String> to = config.getTo();
} catch (Exception e) { MailUtil.sendBySmtp(host, port, true, username, password, from, subject, content, null, to.toArray(new String[to.size()]));
e.printStackTrace(); } catch (Exception e) {
if(tryCount > 0) { e.printStackTrace();
try { if(tryCount > 0) {
Thread.sleep(1000L*60*5); try {
} catch (InterruptedException e1) { Thread.sleep(1000L*60*5);
e1.printStackTrace(); } catch (InterruptedException e1) {
e1.printStackTrace();
}
this.sendForsync(--tryCount, subject, content);
} }
this.sendForsync(--tryCount, subject, content);
} }
} }
} }
......
...@@ -2,4 +2,6 @@ server: ...@@ -2,4 +2,6 @@ server:
port: 9090 port: 9090
spring: spring:
profiles: profiles:
active: dev active: dev
\ No newline at end of file mail:
open: false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment