MailUtils.java
1.58 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.bsth.util;
import com.bsth.email.SimpleMailSender;
import com.bsth.email.entity.EmailBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author Hill
*/
@Component
public class MailUtils {
@Value("${admin.mail}")
private String emailSendToAddress;
private Tools tools = new Tools("mailbox.properties");
private SimpleMailSender sms = new SimpleMailSender(tools.getValue("username"),tools.getValue("password"));
public String getEmailSendToAddress() {
return emailSendToAddress;
}
public void setEmailSendToAddress(String emailSendToAddress) {
this.emailSendToAddress = emailSendToAddress;
}
/**
* recipients
* 收件人集合
* mail
* 邮件
*/
public int sendMail(List<String> recipients, EmailBean mail){
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){
try {
sms.send(recipient, mail.getSubject(),mail.getContent());
} catch (Exception e) {
e.printStackTrace();
return -1;
}
return 1;
}
public int sendMail(EmailBean mail){
return sendMail(emailSendToAddress, mail);
}
}