Commit 6d171823fe6b739732c3c05f944aecad1a11f03c

Authored by 王通
1 parent ff281d6f

1.

src/main/java/com/bsth/util/MailUtils.java
... ... @@ -16,6 +16,10 @@ public class MailUtils {
16 16 @Value("${admin.mail}")
17 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 23 public String getEmailSendToAddress() {
20 24 return emailSendToAddress;
21 25 }
... ... @@ -24,15 +28,13 @@ public class MailUtils {
24 28 this.emailSendToAddress = emailSendToAddress;
25 29 }
26 30  
27   - /*
  31 + /**
28 32 * recipients
29 33 * 收件人集合
30 34 * mail
31 35 * 邮件
32 36 */
33 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 38 try {
37 39 for (String recipient : recipients) {
38 40 sms.send(recipient, mail.getSubject(),mail.getContent());
... ... @@ -44,15 +46,13 @@ public class MailUtils {
44 46 return 1;
45 47 }
46 48  
47   - /*
  49 + /**
48 50 * recipient
49 51 * 收件人
50 52 * mail
51 53 * 邮件
52 54 */
53 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 56 try {
57 57 sms.send(recipient, mail.getSubject(),mail.getContent());
58 58 } catch (Exception e) {
... ... @@ -63,14 +63,6 @@ public class MailUtils {
63 63 }
64 64  
65 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 }
... ...