Commit 6d171823fe6b739732c3c05f944aecad1a11f03c

Authored by 王通
1 parent ff281d6f

1.

src/main/java/com/bsth/util/MailUtils.java
@@ -16,6 +16,10 @@ public class MailUtils { @@ -16,6 +16,10 @@ public class MailUtils {
16 @Value("${admin.mail}") 16 @Value("${admin.mail}")
17 private String emailSendToAddress; 17 private String emailSendToAddress;
18 18
  19 + private Tools tools = new Tools("mailbox.properties");
  20 +
  21 + private SimpleMailSender sms = new SimpleMailSender(tools.getValue("username"),tools.getValue("password"));
  22 +
19 public String getEmailSendToAddress() { 23 public String getEmailSendToAddress() {
20 return emailSendToAddress; 24 return emailSendToAddress;
21 } 25 }
@@ -24,15 +28,13 @@ public class MailUtils { @@ -24,15 +28,13 @@ public class MailUtils {
24 this.emailSendToAddress = emailSendToAddress; 28 this.emailSendToAddress = emailSendToAddress;
25 } 29 }
26 30
27 - /* 31 + /**
28 * recipients 32 * recipients
29 * 收件人集合 33 * 收件人集合
30 * mail 34 * mail
31 * 邮件 35 * 邮件
32 */ 36 */
33 public int sendMail(List<String> recipients, EmailBean mail){ 37 public int sendMail(List<String> recipients, EmailBean mail){
34 - Tools t = new Tools("mailbox.properties");  
35 - SimpleMailSender sms = new SimpleMailSender(t.getValue("username"),t.getValue("password"));  
36 try { 38 try {
37 for (String recipient : recipients) { 39 for (String recipient : recipients) {
38 sms.send(recipient, mail.getSubject(),mail.getContent()); 40 sms.send(recipient, mail.getSubject(),mail.getContent());
@@ -44,15 +46,13 @@ public class MailUtils { @@ -44,15 +46,13 @@ public class MailUtils {
44 return 1; 46 return 1;
45 } 47 }
46 48
47 - /* 49 + /**
48 * recipient 50 * recipient
49 * 收件人 51 * 收件人
50 * mail 52 * mail
51 * 邮件 53 * 邮件
52 */ 54 */
53 public int sendMail(String recipient,EmailBean mail){ 55 public int sendMail(String recipient,EmailBean mail){
54 - Tools t = new Tools("mailbox.properties");  
55 - SimpleMailSender sms = new SimpleMailSender(t.getValue("username"),t.getValue("password"));  
56 try { 56 try {
57 sms.send(recipient, mail.getSubject(),mail.getContent()); 57 sms.send(recipient, mail.getSubject(),mail.getContent());
58 } catch (Exception e) { 58 } catch (Exception e) {
@@ -63,14 +63,6 @@ public class MailUtils { @@ -63,14 +63,6 @@ public class MailUtils {
63 } 63 }
64 64
65 public int sendMail(EmailBean mail){ 65 public int sendMail(EmailBean mail){
66 - Tools t = new Tools("mailbox.properties");  
67 - SimpleMailSender sms = new SimpleMailSender(t.getValue("username"),t.getValue("password"));  
68 - try {  
69 - sms.send(emailSendToAddress, mail.getSubject(),mail.getContent());  
70 - } catch (Exception e) {  
71 - e.printStackTrace();  
72 - return -1;  
73 - }  
74 - return 1; 66 + return sendMail(emailSendToAddress, mail);
75 } 67 }
76 } 68 }