SendEmailController.java
1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.bsth.email;
import com.bsth.email.entity.EmailBean;
import com.bsth.util.Tools;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class SendEmailController {
/*
* recipients
* 收件人集合
* mail
* 邮件
*/
public int sendMail(List<String> recipients,EmailBean mail){
Tools t = new Tools("mailbox.properties");
SimpleMailSender sms = new SimpleMailSender(t.getValue("username"),t.getValue("password"));
try {
for (String recipient : recipients) {
sms.send(recipient, mail.getSubject(),mail.getContent());
}
} catch (Exception e) {
e.printStackTrace();
return -1;
}
return 1;
}
/*
* recipient
* 收件人
* mail
* 邮件
*/
public int sendMail(String recipient,EmailBean mail){
Tools t = new Tools("mailbox.properties");
SimpleMailSender sms = new SimpleMailSender(t.getValue("username"),t.getValue("password"));
try {
sms.send(recipient, mail.getSubject(),mail.getContent());
} catch (Exception e) {
e.printStackTrace();
return -1;
}
return 1;
}
}